-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
💉 feat: Optionally Inject MCP Server Instructions #7660
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
💉 feat: Optionally Inject MCP Server Instructions #7660
Conversation
c6e7863
to
b0c64a1
Compare
@danny-avila I see you marked this PR as work in progress, is there anything that needs to be done to move this forward? |
Hi @benverhees Yes, in my opinion, this should be a configurable pattern, rather than including instructions every time. In fact, I would even make the instructions configurable. The function definitions are already adding a lot to the context. |
b0c64a1
to
cbf690b
Compare
@danny-avila I have added a The
When to Use Each Option
|
a6add81
to
ff25bc5
Compare
@danny-avila if this looks good to you, I'll make a pull request in the docs repo for this. |
ff25bc5
to
b02de73
Compare
@danny-avila is this something you would consider merging, or are there still some things that need improvement? |
@benverhees this is definitely aligned to what I had in mind, thank you! Reviewing now. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull Request Overview
This PR introduces the optional injection of MCP server instructions into the agent’s system context, supporting both ephemeral agents and standard agents with MCP tool associations. Key changes include:
- Adding new logic in MCPManager to store, retrieve, and format MCP server instructions.
- Updating the configuration schema in the data-provider to include the new serverInstructions option.
- Modifying the agent client to extract MCP server names and inject formatted instructions into the system context.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
packages/mcp/src/manager.ts | Implements storage, retrieval, and formatting of server instructions |
packages/data-provider/src/mcp.ts | Updates configuration schema with the serverInstructions field |
api/server/controllers/agents/client.js | Incorporates injection of MCP instructions into agent systemContent |
Comments suppressed due to low confidence (1)
api/server/controllers/agents/client.js:376
- [nitpick] Consider renaming 'mcpServers' to 'mcpServerNames' to better indicate that it holds server name values, which may improve clarity.
let mcpServers = [];
Looks good to me, I will merge to the |
Thanks! I will create a PR in the docs repo! |
@danny-avila documentation is in LibreChat-AI/librechat.ai#321 |
* feat: Add MCP server instructions to context * chore: remove async method as no async code is performed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: remove co-pilot promise resolution --------- Co-authored-by: Danny Avila <danacordially@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
This PR introduces functionality to dynamically inject MCP server instructions into the system context of an agent. This supports both ephemeral agents and standard agents with MCP tool associations. The instructions are retrieved from the MCP server through the client API in the MCPManager and injected in the system content.
MCP server instructions provide high-level context about how to effectively use an entire MCP server - including usage patterns, workflows, and general guidance about the server's capabilities. This is distinct from tool descriptions, which are the specific function-level documentation that describes individual tools' parameters and return values.
This change ensures that comprehensive server-level instructions are automatically available to the agent at runtime, complementing the existing tool descriptions with broader contextual guidance. This improves overall tool usability by providing both the "what" (individual tool descriptions) and the "how" (server usage instructions), reducing the need for hardcoded context-specific behavior.
The
serverInstructions
configuration option provides unified control over instruction behavior:true
: Use server-provided instructionsstring
: Use custom instructions (overrides server-provided)false
: Explicitly disable (same as not setting)When to Use Each Option
serverInstructions: true
Use when the server provides good default instructions:
serverInstructions: "custom instructions"
Use when you need specific guidance:
serverInstructions: false
or not set (default)Use when you prefer minimal context:
Change Type
Please delete any irrelevant options.
Testing
This feature was manually tested by triggering both ephemeral and standard agents with associated MCP tools and verifying that:
Test Configuration:
Environment: Local development with mocked MCP server connections and instructions
Checklist
Please delete any irrelevant options.