File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,38 @@ The MCP servers provide the ability to set a `process_tool_call` which allows
169
169
the customisation of tool call requests and their responses.
170
170
171
171
A common use case for this is to inject metadata to the requests which the server
172
- call needs.
172
+ call needs. Accessing the metadata is then SDK specific, for example with FastMCP
173
+ it is stored in [ Context] ( https://gofastmcp.com/servers/context ) which can be
174
+ injected into the tool handler.
175
+
176
+ ``` python {title="mcp_server.py"}
177
+ from typing import Any
178
+
179
+ from mcp.server.fastmcp import Context, FastMCP
180
+ from mcp.server.session import ServerSession
181
+
182
+ mcp = FastMCP(' Pydantic AI MCP Server' )
183
+ log_level = ' unset'
184
+
185
+
186
+ @mcp.tool ()
187
+ async def echo_deps (ctx : Context[ServerSession, None ]) -> dict[str , Any]:
188
+ """ Echo the run context.
189
+
190
+ Args:
191
+ ctx: Context object containing request and session information.
192
+
193
+ Returns:
194
+ Dictionary with an echo message and the deps.
195
+ """
196
+ await ctx.info(' This is an info message' )
197
+
198
+ deps: Any = getattr (ctx.request_context.meta, ' deps' )
199
+ return {' echo' : ' This is an echo message' , ' deps' : deps}
200
+
201
+ if __name__ == ' __main__' :
202
+ mcp.run()
203
+ ```
173
204
174
205
``` python {title="mcp_process_tool_call.py"}
175
206
from typing import Any
You can’t perform that action at this time.
0 commit comments