Sometimes you have information that you want to pass down to tools via context.
Currently, there is no way for a parent request to initialize context for the server, like this:
app.all("/mcp", async (ctx) => {
const db = ctx.get("db");
const response = await httpHandler(ctx.req.raw, { state: { db } });
return response;
})
Such that tools have access to an underlying database connection:
mcp.tool("my-tool", {
handler: (args, ctx) => {
// ... do something with ctx.state.db
},
})
We will need to employ some optimistic typing tricks similar to Hono to make this happen.
Sometimes you have information that you want to pass down to tools via context.
Currently, there is no way for a parent request to initialize context for the server, like this:
Such that tools have access to an underlying database connection:
We will need to employ some optimistic typing tricks similar to Hono to make this happen.