How to access Hono Context from within @hono/mcp tool definition #4452
-
| 
         I'm building with https://www.npmjs.com/package/@hono/mcp How can I access the Hono Context from within a tool call definition, to get things like env vars? import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StreamableHTTPTransport } from '@hono/mcp'
import { Hono } from 'hono'
const app = new Hono()
// Your MCP server implementation
const mcpServer = new McpServer({
  name: 'my-mcp-server',
  version: '1.0.0',
})
// Register tools
server.registerTool(
  "test",
  {
    title: "Test Tool",
    inputSchema: {},
    outputSchema: { … },
  },
  async () => {
    // ! How to access c (var and env) from here?
  },
);
app.all('/mcp', async (c) => {
  const transport = new StreamableHTTPTransport()
  await mcpServer.connect(transport)
  return transport.handleRequest(c)
})
export default app@MathurAditya724 could you help me with this?  | 
  
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            MathurAditya724
          
      
      
        Oct 8, 2025 
      
    
    Replies: 1 comment
-
| 
         Use this - https://hono.dev/docs/middleware/builtin/context-storage You will then be able to access the context variable from anywhere  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        abegehr
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Use this - https://hono.dev/docs/middleware/builtin/context-storage
You will then be able to access the context variable from anywhere