@kontent-ai/mcp-server 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +26 -0
  2. package/build/bin.js +67 -3
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -159,6 +159,30 @@ Then configure your MCP client:
159
159
  }
160
160
  ```
161
161
 
162
+ ### 🌊 Streamable HTTP Transport
163
+
164
+ For Streamable HTTP transport, first start the server:
165
+
166
+ ```bash
167
+ npx @kontent-ai/mcp-server@latest shttp
168
+ ```
169
+
170
+ With environment variables in a `.env` file, or otherwise accessible to the process:
171
+ ```env
172
+ KONTENT_API_KEY=<management-api-key>
173
+ KONTENT_ENVIRONMENT_ID=<environment-id>
174
+ PORT=3001 # optional, defaults to 3001
175
+ ```
176
+
177
+ Then configure your MCP client:
178
+ ```json
179
+ {
180
+ "kontent-ai-http": {
181
+ "url": "http://localhost:3001/mcp"
182
+ }
183
+ }
184
+ ```
185
+
162
186
  ## 💻 Development
163
187
 
164
188
  ### 🛠 Local Installation
@@ -177,10 +201,12 @@ npm run build
177
201
  # Start the server
178
202
  npm run start:sse # For SSE transport
179
203
  npm run start:stdio # For STDIO transport
204
+ npm run start:shttp # For Streamable HTTP transport
180
205
 
181
206
  # Start the server with automatic reloading (no need to build first)
182
207
  npm run dev:sse # For SSE transport
183
208
  npm run dev:stdio # For STDIO transport
209
+ npm run dev:shttp # For Streamable HTTP transport
184
210
  ```
185
211
 
186
212
  ### 📂 Project Structure
package/build/bin.js CHANGED
@@ -1,11 +1,70 @@
1
1
  #!/usr/bin/env node
2
- import "dotenv/config";
3
2
  import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
4
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
+ import "dotenv/config";
5
6
  import express from "express";
6
7
  import packageJson from "../package.json" with { type: "json" };
7
8
  import { createServer } from "./server.js";
8
9
  const version = packageJson.version;
10
+ async function startStreamableHTTP() {
11
+ const app = express();
12
+ app.use(express.json());
13
+ app.post("/mcp", async (req, res) => {
14
+ try {
15
+ const { server } = createServer();
16
+ const transport = new StreamableHTTPServerTransport({
17
+ sessionIdGenerator: undefined,
18
+ });
19
+ res.on("close", () => {
20
+ console.log("Request closed");
21
+ transport.close();
22
+ server.close();
23
+ });
24
+ await server.connect(transport);
25
+ await transport.handleRequest(req, res, req.body);
26
+ }
27
+ catch (error) {
28
+ console.error("Error handling MCP request:", error);
29
+ if (!res.headersSent) {
30
+ res.status(500).json({
31
+ jsonrpc: "2.0",
32
+ error: {
33
+ code: -32603,
34
+ message: "Internal server error",
35
+ },
36
+ id: null,
37
+ });
38
+ }
39
+ }
40
+ });
41
+ app.get("/mcp", async (_, res) => {
42
+ console.log("Received GET MCP request");
43
+ res.writeHead(405).end(JSON.stringify({
44
+ jsonrpc: "2.0",
45
+ error: {
46
+ code: -32000,
47
+ message: "Method not allowed.",
48
+ },
49
+ id: null,
50
+ }));
51
+ });
52
+ app.delete("/mcp", async (_, res) => {
53
+ console.log("Received DELETE MCP request");
54
+ res.writeHead(405).end(JSON.stringify({
55
+ jsonrpc: "2.0",
56
+ error: {
57
+ code: -32000,
58
+ message: "Method not allowed.",
59
+ },
60
+ id: null,
61
+ }));
62
+ });
63
+ const PORT = process.env.PORT || 3001;
64
+ app.listen(PORT, () => {
65
+ console.log(`Kontent.ai MCP Server v${version} (Streamable HTTP) running on port ${PORT}`);
66
+ });
67
+ }
9
68
  async function startSSE() {
10
69
  const app = express();
11
70
  const { server } = createServer();
@@ -32,8 +91,10 @@ async function main() {
32
91
  const args = process.argv.slice(2);
33
92
  const transportType = args[0]?.toLowerCase();
34
93
  if (!transportType ||
35
- (transportType !== "stdio" && transportType !== "sse")) {
36
- console.error("Please specify a valid transport type: stdio or sse");
94
+ (transportType !== "stdio" &&
95
+ transportType !== "sse" &&
96
+ transportType !== "shttp")) {
97
+ console.error("Please specify a valid transport type: stdio, sse, or shttp");
37
98
  process.exit(1);
38
99
  }
39
100
  if (transportType === "stdio") {
@@ -42,6 +103,9 @@ async function main() {
42
103
  else if (transportType === "sse") {
43
104
  await startSSE();
44
105
  }
106
+ else if (transportType === "shttp") {
107
+ await startStreamableHTTP();
108
+ }
45
109
  }
46
110
  main().catch((error) => {
47
111
  console.error("Fatal error:", error);
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@kontent-ai/mcp-server",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "rimraf build && tsc",
7
7
  "start:stdio": "node build/bin.js stdio",
8
8
  "start:sse": "node build/bin.js sse",
9
+ "start:shttp": "node build/bin.js shttp",
9
10
  "dev:stdio": "tsx watch src/bin.ts stdio",
10
11
  "dev:sse": "tsx watch src/bin.ts sse",
12
+ "dev:shttp": "tsx watch src/bin.ts shttp",
11
13
  "format": "cross-env node node_modules/@biomejs/biome/bin/biome ci ./ --config-path=./biome.json",
12
14
  "format:fix": "cross-env node node_modules/@biomejs/biome/bin/biome check ./ --fix --unsafe --config-path=./biome.json"
13
15
  },