mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-13 06:28:29 +00:00
Feat: add mcp support to chat
This commit is contained in:
parent
f2b4a5f64a
commit
32379a0b0e
@ -262,6 +262,7 @@ export async function* run(
|
||||
let guardLoop = 0;
|
||||
|
||||
let tools = {
|
||||
...(await mcp.allTools()),
|
||||
"core--progress_update": progressUpdateTool,
|
||||
"core--search_memory": searchMemoryTool,
|
||||
"core--add_memory": addMemoryTool,
|
||||
|
||||
@ -37,9 +37,11 @@ export const chat = task({
|
||||
|
||||
const { previousHistory, ...otherData } = payload.context;
|
||||
|
||||
const { agents = [] } = payload.context;
|
||||
// Initialise mcp
|
||||
const mcp = new MCP();
|
||||
await mcp.init();
|
||||
await mcp.load(agents, { Authorization: `Bearer ${init?.token}` });
|
||||
|
||||
// Prepare context with additional metadata
|
||||
const context = {
|
||||
|
||||
@ -3,7 +3,7 @@ import { logger } from "@trigger.dev/sdk/v3";
|
||||
import { jsonSchema, tool, type ToolSet } from "ai";
|
||||
|
||||
import { type MCPTool } from "./types";
|
||||
|
||||
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||
export class MCP {
|
||||
private Client: any;
|
||||
private clients: Record<string, any> = {};
|
||||
@ -23,15 +23,14 @@ export class MCP {
|
||||
return Client;
|
||||
}
|
||||
|
||||
async load(agents: string[], mcpConfig: any) {
|
||||
async load(agents: string[], headers: any) {
|
||||
await Promise.all(
|
||||
agents.map(async (agent) => {
|
||||
const mcp = mcpConfig.mcpServers[agent];
|
||||
|
||||
return await this.connectToServer(agent, mcp.command, mcp.args, {
|
||||
...mcp.env,
|
||||
DATABASE_URL: mcp.env?.DATABASE_URL ?? "",
|
||||
});
|
||||
return await this.connectToServer(
|
||||
agent,
|
||||
`${process.env.BACKEND_HOST}/api/v1/mcp/${agent}`,
|
||||
headers,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
@ -113,12 +112,7 @@ export class MCP {
|
||||
return response;
|
||||
}
|
||||
|
||||
async connectToServer(
|
||||
name: string,
|
||||
command: string,
|
||||
args: string[],
|
||||
env: any,
|
||||
) {
|
||||
async connectToServer(name: string, url: string, headers: any) {
|
||||
try {
|
||||
const client = new this.Client(
|
||||
{
|
||||
@ -130,12 +124,9 @@ export class MCP {
|
||||
},
|
||||
);
|
||||
|
||||
// Conf
|
||||
// igure the transport for MCP server
|
||||
const transport = new this.StdioTransport({
|
||||
command,
|
||||
args,
|
||||
env,
|
||||
// Configure the transport for MCP server
|
||||
const transport = new StreamableHTTPClientTransport(new URL(url), {
|
||||
requestInit: { headers },
|
||||
});
|
||||
|
||||
// Connect to the MCP server
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user