Skip to content

InjectedState in MCP tools #287

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

streamnsight
Copy link

@streamnsight streamnsight commented Aug 14, 2025

usage:
On the MCP server side, specify the key to map to the state with annotations:

@mcp.tool(annotations={"injected_state": "state"}) 
def tool(a: int = 0, b: Union[str, None] = None, state):
   pass

On the client side, it is handled automatically by the added code.

Caveat:

  • trying to parse most types (base type, List, Unions, Literal, Optional) and default values, but probably not complete.
  • no implementation for the converter from langchain tool to mcp tool at the moment

usage:
On the MCP server side, specify the key to map to the state with annotations:
@mcp.tool(annotations={"injected_state": "state"})
def tool(a, b, state):
   pass

On the client side, it is handled automatically
@streamnsight streamnsight marked this pull request as ready for review August 15, 2025 21:11
@streamnsight
Copy link
Author

@eyurtsev for review.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant