Skip to content

Commit da66fa3

Browse files
committed
Add LLMContextRouter
1 parent 2c0bd62 commit da66fa3

File tree

5 files changed

+299
-33
lines changed

5 files changed

+299
-33
lines changed

.changeset/sharp-bears-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
Add ContextRouter to allow users to provide an LLM with a list of filtered tools and resources

packages/agents/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
"types": "./dist/mcp/do-oauth-client-provider.d.ts",
6969
"require": "./dist/mcp/do-oauth-client-provider.js",
7070
"import": "./dist/mcp/do-oauth-client-provider.js"
71+
},
72+
"./mcp/context-router": {
73+
"types": "./dist/mcp/context-router.d.ts",
74+
"require": "./dist/mcp/context-router.js",
75+
"import": "./dist/mcp/context-router.js"
7176
}
7277
},
7378
"keywords": [],

packages/agents/scripts/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async function main() {
99
"src/mcp/index.ts",
1010
"src/mcp/client.ts",
1111
"src/mcp/do-oauth-client-provider.ts",
12+
"src/mcp/context-router.ts",
1213
],
1314
splitting: true,
1415
sourcemap: true,

packages/agents/src/mcp/client.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export class MCPClientManager {
3434
constructor(
3535
private _name: string,
3636
private _version: string,
37-
public unstable_contextRouter = new BaseContextRouter(),
38-
) {}
37+
public unstable_contextRouter: ContextRouter = new BaseContextRouter()
38+
) {
39+
this.unstable_contextRouter.clientManager = this;
40+
}
3941

4042
/**
4143
* Connect to and register an MCP server
@@ -204,21 +206,21 @@ export class MCPClientManager {
204206
* @returns namespaced list of tools
205207
*/
206208
listTools(): NamespacedData["tools"] {
207-
return this.unstable_contextRouter.listTools(this)
209+
return this.unstable_contextRouter.listTools();
208210
}
209211

210212
/**
211213
* @returns a set of tools that you can use with the AI SDK
212214
*/
213215
unstable_getAITools(): ToolSet {
214-
return this.unstable_contextRouter.getAITools(this)
216+
return this.unstable_contextRouter.getAITools();
215217
}
216218

217219
/**
218220
* @returns namespaced list of tools
219221
*/
220222
listResources(): NamespacedData["resources"] {
221-
return this.unstable_contextRouter.listResources(this);
223+
return this.unstable_contextRouter.listResources();
222224
}
223225

224226
/**
@@ -288,7 +290,7 @@ export class MCPClientManager {
288290
* @param includeResources Whether to include resources in the prompt. This may be useful if you include a tool to fetch resources OR if the servers you connect to interact with resources.
289291
*/
290292
unstable_systemPrompt(): string {
291-
return this.unstable_contextRouter.systemPrompt(this)
293+
return this.unstable_contextRouter.systemPrompt();
292294
}
293295
}
294296

0 commit comments

Comments
 (0)