-
Notifications
You must be signed in to change notification settings - Fork 332
Add ContextRouter #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add ContextRouter #275
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "agents": patch | ||
| --- | ||
|
|
||
| Add unstable_getMcpPrompt to provide LLM consumable MCP integration context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { MCPClientConnection } from "./client-connection"; | ||
| import type { Resource } from "@modelcontextprotocol/sdk/types.js"; | ||
|
|
||
| export function unstable_getMcpPrompt( | ||
| conns: Record<string, MCPClientConnection>, | ||
| includeResources: boolean | ||
| ) { | ||
| return `<integrations_list> | ||
| You have access to multiple integrations via Model Context Protocol (MCP). These integrations provide you with tools which you can use to execute to complete tasks or retrieive information. | ||
| ${includeResources && "Each integration, provides a list of resources, which are included in the list of integrations below."} | ||
| Here is a list of all of the integrations you have access to, with instructions if necessary: | ||
| ${Object.entries(conns).map(([_id, conn]) => serverContext(conn, includeResources))} | ||
| <integrations_list>`; | ||
| } | ||
|
|
||
| function serverContext(conn: MCPClientConnection, includeResources: boolean) { | ||
| return `<integration> | ||
| ${conn.serverInfo && `<integration_name>${conn.serverInfo.name}</integration_name>`} | ||
| ${conn.instructions && `<integration_instructions>${conn.instructions}</integration_instructions>`} | ||
| ${includeResources && `<resources_list>${conn.resources.map((resource) => resourceContext(resource))}</resources_list>`} | ||
| <integration>`; | ||
| } | ||
|
|
||
| function resourceContext(resource: Resource) { | ||
| return `<resource> | ||
| <name>${resource.name}</name> | ||
| <uri>${resource.uri}</uri> | ||
| <description>${resource.description}</description> | ||
| <mimeType>${resource.mimeType}</mimeType> | ||
| </resource>`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.j | |
| import type { AgentsOAuthProvider } from "./do-oauth-client-provider"; | ||
| import { jsonSchema, type ToolSet } from "ai"; | ||
| import { nanoid } from "nanoid"; | ||
| import { unstable_getMcpPrompt } from "./client-prompt"; | ||
|
|
||
| /** | ||
| * Utility class that aggregates multiple MCP clients into one | ||
|
|
@@ -301,6 +302,15 @@ export class MCPClientManager { | |
| options | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Utility function to fetch MCP information which you can add to an LLM's system prompt. | ||
| * | ||
| * @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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function no longer has a parameter |
||
| */ | ||
| unstable_getMcpPrompt(includeResources = true): string { | ||
cmsparks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return unstable_getMcpPrompt(this.mcpConnections, includeResources); | ||
| } | ||
| } | ||
|
|
||
| type NamespacedData = { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retrieive -> retrieve
which you can use to execute -> which you can execute