-
Notifications
You must be signed in to change notification settings - Fork 2
feat(setup mcp): add initial mcp integration #678
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
+125
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b5ea31
feat(mcp): add initial mcp server setup
akulistus 6b6996c
remove duplication
akulistus a8ac317
chore(mcp): add comments, fix transport single instance issue
akulistus 58cc815
Bump version up to 1.5.11
github-actions[bot] 6bf916c
Merge branch 'master' into feat/setup-mcp
akulistus 6814c54
Bump version up to 1.5.14
github-actions[bot] 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
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,15 @@ | ||
| import express from 'express'; | ||
| import { ContextFactories } from 'src/types/graphql'; | ||
| import { createMCPRouter } from "./mcp"; | ||
|
|
||
| /** | ||
| * Append MCP route to Express App | ||
| * | ||
| * @param app - Express application instance | ||
| * @param factories - context factories for database access | ||
| */ | ||
| export function appendMCPRoutes(app: express.Application, factories: ContextFactories): void { | ||
| const router = createMCPRouter(factories); | ||
|
|
||
| app.use('/integration/mcp', router); | ||
| } |
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,68 @@ | ||
| import express from "express"; | ||
| import { McpServer } from '@modelcontextprotocol/server'; | ||
| import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node'; | ||
| import { ContextFactories } from 'src/types/graphql'; | ||
|
|
||
| /** | ||
| * Create MCP router | ||
| * | ||
| * @param factories - context factories for database access | ||
| * @returns Express router with MCP integration endpoints | ||
| */ | ||
| export const createMCPRouter = (factories: ContextFactories): express.Router => { | ||
| const router = express.Router(); | ||
| const server = createMCPServer(factories); | ||
|
|
||
| /** | ||
| * POST /integration/mcp | ||
| * Initiate MCP integration connection | ||
| */ | ||
| router.post("/", async (req, res, next) => { | ||
| try { | ||
| /** | ||
| * Each request must use its own transport | ||
| */ | ||
| const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined }); | ||
| await server.connect(transport); | ||
|
|
||
| await transport.handleRequest(req, res, req.body); | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }); | ||
|
|
||
| return router; | ||
| }; | ||
|
|
||
| /** | ||
| * Create MCP server | ||
| * | ||
| * @param factories - context factories for database access | ||
| * @returns configured MCP server | ||
| */ | ||
| const createMCPServer = (factories: ContextFactories) => { | ||
| const server = new McpServer({ | ||
| name: "server", | ||
| version: "0.0.0", | ||
| description: "A test server" | ||
| }); | ||
|
|
||
| server.registerTool( | ||
| "hello_world", | ||
| { | ||
| description: "A test tool to greet the user" | ||
| }, | ||
| async () => { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text" as const, | ||
| text: "Hi" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| return server; | ||
| }; | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MCP Streamable HTTP transport defines
GETrequests to establish SSE streams andDELETErequests to terminate sessions, but mounting onlyrouter.postcauses Express to reject them with 404 Not Found. Usingrouter.allallowsNodeStreamableHTTPServerTransportto handle all standard MCP HTTP methods.