-
Notifications
You must be signed in to change notification settings - Fork 41
feat(mcp): support custom JSON-RPC methods and capabilities #2420
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
zensucht
wants to merge
6
commits into
graphql-hive:main
Choose a base branch
from
zensucht:feat/mcp-graphql-jsonrpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8c60d0a
refactor(mcp): extract built-in method dispatch into a registry
zensucht 14dc56d
fix(mcp): suppress responses for unknown notification methods
zensucht 6514ea4
feat(mcp): support custom JSON-RPC methods and capabilities
zensucht 3a14272
fix(mcp): harden custom method dispatch and config validation
zensucht 09ad6fa
fix(mcp): complete hop-by-hop header stripping and reject non-OK inte…
zensucht 19bfba3
Merge branch 'main' into feat/mcp-graphql-jsonrpc
zensucht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@graphql-hive/plugin-mcp': minor | ||
| --- | ||
|
|
||
| Add `customMethods` and `customCapabilities` to the MCP plugin configuration. Custom JSON-RPC methods are dispatched on the MCP endpoint alongside the built-ins and receive a context with `executeGraphQL` (full server pipeline, request headers forwarded), `getSchema`, and transport details. Throw the new `MCPMethodError` from a handler to produce a JSON-RPC error response with a specific code. Custom capability entries are merged into the `initialize` response. Unknown `notifications/*` methods are now silently dropped instead of receiving a "Method not found" error response, per the JSON-RPC 2.0 specification. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { Logger } from '@graphql-hive/gateway-runtime'; | ||
| import type { ExecutionResult, GraphQLSchema } from 'graphql'; | ||
|
|
||
| /** A GraphQL operation submitted through {@link MCPMethodContext.executeGraphQL}. */ | ||
| export interface MCPGraphQLOperation { | ||
| query: string; | ||
| variables?: Record<string, unknown>; | ||
| operationName?: string; | ||
| } | ||
|
|
||
| /** Transport details for the request that carried a custom method call. */ | ||
| export type MCPMethodTransport = { | ||
| type: 'http'; | ||
| /** The incoming HTTP request. */ | ||
| request: Request; | ||
| /** Lower-cased HTTP request headers. */ | ||
| headers: Record<string, string>; | ||
| }; | ||
|
|
||
| /** Request metadata and server capabilities available to a custom MCP method handler. */ | ||
| export interface MCPMethodContext { | ||
| /** Plugin logger, scoped with the MCP prefix. */ | ||
| logger: Logger; | ||
| /** The JSON-RPC method name that was dispatched. */ | ||
| method: string; | ||
| /** The JSON-RPC request id, or null for notifications. */ | ||
| requestId: string | number | null; | ||
| /** | ||
| * Execute a GraphQL operation through the full server pipeline. | ||
| * Request headers are forwarded, so authentication and other | ||
| * header-driven plugins behave as if the operation arrived over HTTP. | ||
| * The operation shares the incoming request's server context, so | ||
| * plugins that key state on context identity see it as part of the | ||
| * surrounding MCP request. | ||
| */ | ||
| executeGraphQL(operation: MCPGraphQLOperation): Promise<ExecutionResult>; | ||
| /** The current GraphQL schema. */ | ||
| getSchema(): GraphQLSchema; | ||
| /** Transport details for the current request, when available. */ | ||
| transport?: MCPMethodTransport; | ||
| } | ||
|
|
||
| /** | ||
| * Handler for a custom JSON-RPC method on the MCP endpoint. `params` | ||
| * arrives exactly as sent by the client and may be undefined. The return | ||
| * value must be JSON-serializable and becomes the JSON-RPC `result`. | ||
| * Throw {@link MCPMethodError} to produce a JSON-RPC error response | ||
| * with a specific code. | ||
| */ | ||
| export type MCPMethodHandler = ( | ||
| params: unknown, | ||
| context: MCPMethodContext, | ||
| ) => Promise<unknown> | unknown; | ||
|
|
||
| /** Thrown by a custom method handler to produce a JSON-RPC error response. */ | ||
| export class MCPMethodError extends Error { | ||
| constructor( | ||
| /** JSON-RPC error code (e.g. -32602 for invalid params). */ | ||
| readonly code: number, | ||
| message: string, | ||
| /** Optional structured details serialized into the error `data` field. */ | ||
| readonly data?: unknown, | ||
| ) { | ||
| super(message); | ||
| this.name = 'MCPMethodError'; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.