feat(hono): add generic Env type support to createMcpHonoApp#1878
Open
dagangtj wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat(hono): add generic Env type support to createMcpHonoApp#1878dagangtj wants to merge 1 commit intomodelcontextprotocol:mainfrom
dagangtj wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
- Add generic type parameter E extends BlankEnv = BlankEnv to createMcpHonoApp - Pass generic type to Hono<E> constructor for proper type inference - Update Context type to Context<E> for typed middleware support - Add usage example in JSDoc showing Cloudflare Workers pattern - Add tests for generic type support and backward compatibility Fixes modelcontextprotocol#1877
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds generic type support to `createMcpHonoApp` to allow users to specify custom Env types, enabling proper type inference for environment bindings (like Cloudflare D1) and variables within MCP handlers.
Changes
Usage Example
```typescript
// With custom Env type for Cloudflare Workers
type Env = {
Bindings: {
DB: D1Database;
};
Variables: {
user: User;
};
};
const app = createMcpHonoApp();
app.get('/data', async (c) => {
const db = c.env.DB; // typed as D1Database
const user = c.get('user'); // typed as User
// ...
});
```
Backward Compatibility
This change is fully backward compatible - existing code using `createMcpHonoApp()` without a generic parameter will continue to work exactly as before (defaults to `BlankEnv`).
Related Issue
Fixes #1877