Repository navigation
feat: prepare MCP server as stdio-only npm package #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
45024f6
feat: prepare MCP server as stdio-only npm package
Mgrdich 1195cfb
docs: update README for stdio-only npm package distribution
Mgrdich 9a92659
docs: add Installation & Usage section for end users
Mgrdich 7055ec2
docs: update package references to @provectus scope
Mgrdich 00f1972
fix: add packageManager field to fix CI pnpm setup
Mgrdich c2e20da
feat: add npm publishing with OIDC provenance
Mgrdich ffd9dd5
fix: address PR review comments
Mgrdich 0c2eecd
docs: pin npx install to @latest tag
Mgrdich ed8ba5c
chore: remove npm publish and release drafter workflows
Mgrdich 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,83 +1,17 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | ||
| import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"; | ||
| import { createServer as createHttpServer } from "http"; | ||
| import { join } from "path"; | ||
| import { dirname, join } from "path"; | ||
| import { fileURLToPath } from "url"; | ||
| import { loadPlugins } from "./loader.js"; | ||
| import { createServer } from "./server.js"; | ||
|
|
||
| const pluginsDir = join(process.cwd(), "plugins"); | ||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const pluginsDir = join(__dirname, "..", "plugins"); | ||
|
|
||
| const plugins = loadPlugins(pluginsDir); | ||
| console.error(`Loaded ${plugins.length} plugins`); | ||
|
|
||
| const MAX_BODY_SIZE = 1024 * 1024; // 1 MB | ||
|
|
||
| const portEnv = process.env.PORT; | ||
| let port: number | undefined; | ||
|
|
||
| if (portEnv !== undefined) { | ||
| const parsed = Number(portEnv); | ||
| if (!Number.isFinite(parsed) || !Number.isInteger(parsed) || parsed < 0) { | ||
| console.error(`Invalid PORT value "${portEnv}". Expected a non-negative integer.`); | ||
| process.exit(1); | ||
| } | ||
| port = parsed; | ||
| } | ||
|
|
||
| if (port !== undefined) { | ||
| const httpServer = createHttpServer(async (req, res) => { | ||
| if (req.url === "/mcp" && req.method === "POST") { | ||
| const server = createServer(plugins); | ||
| const transport = new StreamableHTTPServerTransport({ | ||
| sessionIdGenerator: undefined, | ||
| }); | ||
|
|
||
| try { | ||
| await server.connect(transport); | ||
|
|
||
| const body = await new Promise<string>((resolve, reject) => { | ||
| let data = ""; | ||
| let size = 0; | ||
| req.on("data", (chunk: Buffer) => { | ||
| size += chunk.length; | ||
| if (size > MAX_BODY_SIZE) { | ||
| req.destroy(); | ||
| reject(new Error("Request body too large")); | ||
| return; | ||
| } | ||
| data += chunk; | ||
| }); | ||
| req.on("end", () => resolve(data)); | ||
| req.on("error", reject); | ||
| }); | ||
|
|
||
| await transport.handleRequest(req, res, JSON.parse(body)); | ||
| } catch (err) { | ||
| if (!res.headersSent) { | ||
| const status = err instanceof Error && err.message === "Request body too large" ? 413 : 400; | ||
| res.writeHead(status, { "Content-Type": "application/json" }); | ||
| res.end(JSON.stringify({ error: status === 413 ? "Request body too large" : "Bad request" })); | ||
| } | ||
| } finally { | ||
| transport.close(); | ||
| server.close(); | ||
| } | ||
| } else { | ||
| res.writeHead(404, { "Content-Type": "application/json" }); | ||
| res.end(JSON.stringify({ error: "Not found" })); | ||
| } | ||
| }); | ||
|
|
||
| httpServer.listen(port, () => { | ||
| console.error(`MCP HTTP server listening on port ${port}`); | ||
| }); | ||
|
|
||
| process.on("SIGINT", () => { | ||
| httpServer.close(); | ||
| process.exit(0); | ||
| }); | ||
| } else { | ||
| const server = createServer(plugins); | ||
| const transport = new StdioServerTransport(); | ||
| await server.connect(transport); | ||
| } | ||
| const server = createServer(plugins); | ||
| const transport = new StdioServerTransport(); | ||
| await server.connect(transport); |
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.