@jaypie/mcp 0.1.2 → 0.1.3

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.
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Finlayson Studio, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ /**
3
+ * Creates and configures an MCP server instance with Jaypie tools
4
+ * @param version - The version string for the server
5
+ * @returns Configured MCP server instance
6
+ */
7
+ export declare function createMcpServer(version?: string): McpServer;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- declare const server: McpServer;
4
- export { server };
2
+ export { createMcpServer } from "./createMcpServer.js";
3
+ export { mcpExpressHandler, type McpExpressHandlerOptions, } from "./mcpExpressHandler.js";
package/dist/index.js CHANGED
@@ -1,23 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { z } from 'zod';
5
5
  import * as fs from 'fs/promises';
6
6
  import * as path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import matter from 'gray-matter';
9
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
10
+ import { randomUUID } from 'crypto';
9
11
 
10
- // Version will be injected during build
11
- const version = "0.0.0";
12
12
  const __filename = fileURLToPath(import.meta.url);
13
13
  const __dirname = path.dirname(__filename);
14
14
  const PROMPTS_PATH = path.join(__dirname, "..", "prompts");
15
- const server = new McpServer({
16
- name: "jaypie",
17
- version,
18
- }, {
19
- capabilities: {},
20
- });
21
15
  async function parseMarkdownFile(filePath) {
22
16
  try {
23
17
  const content = await fs.readFile(filePath, "utf-8");
@@ -52,76 +46,145 @@ function formatPromptListItem(prompt) {
52
46
  return `* ${filename}`;
53
47
  }
54
48
  }
55
- server.tool("list_prompts", "Returns a bulleted list of all .md files in the prompts directory with their descriptions and requirements", {}, async () => {
56
- try {
57
- const files = await fs.readdir(PROMPTS_PATH);
58
- const mdFiles = files.filter((file) => file.endsWith(".md"));
59
- const prompts = await Promise.all(mdFiles.map((file) => parseMarkdownFile(path.join(PROMPTS_PATH, file))));
60
- const formattedList = prompts.map(formatPromptListItem).join("\n");
61
- return {
62
- content: [
63
- {
64
- type: "text",
65
- text: formattedList || "No .md files found in the prompts directory.",
66
- },
67
- ],
68
- };
69
- }
70
- catch (error) {
71
- return {
72
- content: [
73
- {
74
- type: "text",
75
- text: `Error listing prompts: ${error instanceof Error ? error.message : "Unknown error"}`,
76
- },
77
- ],
78
- };
79
- }
80
- });
81
- server.tool("read_prompt", "Returns the contents of a specified prompt file", {
82
- filename: z
83
- .string()
84
- .describe("The name of the prompt file to read (e.g., example_prompt.md)"),
85
- }, async ({ filename }) => {
86
- try {
87
- const filePath = path.join(PROMPTS_PATH, filename);
88
- const content = await fs.readFile(filePath, "utf-8");
89
- return {
90
- content: [
91
- {
92
- type: "text",
93
- text: content,
94
- },
95
- ],
96
- };
97
- }
98
- catch (error) {
99
- if (error.code === "ENOENT") {
49
+ /**
50
+ * Creates and configures an MCP server instance with Jaypie tools
51
+ * @param version - The version string for the server
52
+ * @returns Configured MCP server instance
53
+ */
54
+ function createMcpServer(version = "0.0.0") {
55
+ const server = new McpServer({
56
+ name: "jaypie",
57
+ version,
58
+ }, {
59
+ capabilities: {},
60
+ });
61
+ server.tool("list_prompts", "Returns a bulleted list of all .md files in the prompts directory with their descriptions and requirements", {}, async () => {
62
+ try {
63
+ const files = await fs.readdir(PROMPTS_PATH);
64
+ const mdFiles = files.filter((file) => file.endsWith(".md"));
65
+ const prompts = await Promise.all(mdFiles.map((file) => parseMarkdownFile(path.join(PROMPTS_PATH, file))));
66
+ const formattedList = prompts.map(formatPromptListItem).join("\n");
100
67
  return {
101
68
  content: [
102
69
  {
103
70
  type: "text",
104
- text: `Error: Prompt file "${filename}" not found in prompts directory`,
71
+ text: formattedList || "No .md files found in the prompts directory.",
105
72
  },
106
73
  ],
107
74
  };
108
75
  }
109
- return {
110
- content: [
111
- {
112
- type: "text",
113
- text: `Error reading prompt file: ${error instanceof Error ? error.message : "Unknown error"}`,
114
- },
115
- ],
116
- };
117
- }
118
- });
76
+ catch (error) {
77
+ return {
78
+ content: [
79
+ {
80
+ type: "text",
81
+ text: `Error listing prompts: ${error instanceof Error ? error.message : "Unknown error"}`,
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ });
87
+ server.tool("read_prompt", "Returns the contents of a specified prompt file", {
88
+ filename: z
89
+ .string()
90
+ .describe("The name of the prompt file to read (e.g., example_prompt.md)"),
91
+ }, async ({ filename }) => {
92
+ try {
93
+ const filePath = path.join(PROMPTS_PATH, filename);
94
+ const content = await fs.readFile(filePath, "utf-8");
95
+ return {
96
+ content: [
97
+ {
98
+ type: "text",
99
+ text: content,
100
+ },
101
+ ],
102
+ };
103
+ }
104
+ catch (error) {
105
+ if (error.code === "ENOENT") {
106
+ return {
107
+ content: [
108
+ {
109
+ type: "text",
110
+ text: `Error: Prompt file "${filename}" not found in prompts directory`,
111
+ },
112
+ ],
113
+ };
114
+ }
115
+ return {
116
+ content: [
117
+ {
118
+ type: "text",
119
+ text: `Error reading prompt file: ${error instanceof Error ? error.message : "Unknown error"}`,
120
+ },
121
+ ],
122
+ };
123
+ }
124
+ });
125
+ return server;
126
+ }
127
+
128
+ // Version will be injected during build
129
+ const DEFAULT_VERSION = "0.0.0";
130
+ /**
131
+ * Creates an Express handler for the Jaypie MCP server using HTTP transport
132
+ *
133
+ * @param options - Configuration options for the handler
134
+ * @returns Express middleware function
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * import express from 'express';
139
+ * import { mcpExpressHandler } from '@jaypie/mcp';
140
+ *
141
+ * const app = express();
142
+ * app.use(express.json());
143
+ *
144
+ * app.use('/mcp', mcpExpressHandler({
145
+ * version: '1.0.0',
146
+ * enableSessions: true
147
+ * }));
148
+ *
149
+ * app.listen(3000, () => {
150
+ * console.log('MCP server running on http://localhost:3000/mcp');
151
+ * });
152
+ * ```
153
+ */
154
+ function mcpExpressHandler(options = {}) {
155
+ const { version = DEFAULT_VERSION, enableSessions = true, sessionIdGenerator = () => randomUUID(), enableJsonResponse = false, } = options;
156
+ const server = createMcpServer(version);
157
+ const transport = new StreamableHTTPServerTransport({
158
+ sessionIdGenerator: enableSessions ? sessionIdGenerator : undefined,
159
+ enableJsonResponse,
160
+ });
161
+ server.connect(transport);
162
+ return async (req, res) => {
163
+ try {
164
+ await transport.handleRequest(req, res, req.body);
165
+ }
166
+ catch (error) {
167
+ if (!res.headersSent) {
168
+ res.status(500).json({
169
+ error: "Internal server error",
170
+ message: error instanceof Error ? error.message : "Unknown error",
171
+ });
172
+ }
173
+ }
174
+ };
175
+ }
176
+
177
+ // Version will be injected during build
178
+ const version = "0.0.0";
119
179
  async function main() {
180
+ const server = createMcpServer(version);
120
181
  const transport = new StdioServerTransport();
121
182
  await server.connect(transport);
122
183
  // Server is running on stdio
123
184
  }
124
- main();
185
+ if (import.meta.url === `file://${process.argv[1]}`) {
186
+ main();
187
+ }
125
188
 
126
- export { server };
189
+ export { createMcpServer, mcpExpressHandler };
127
190
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { z } from \"zod\";\nimport * as fs from \"fs/promises\";\nimport * as path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport matter from \"gray-matter\";\n// Version will be injected during build\nconst version = \"0.0.0\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst PROMPTS_PATH = path.join(__dirname, \"..\", \"prompts\");\n\nconst server = new McpServer(\n {\n name: \"jaypie\",\n version,\n },\n {\n capabilities: {},\n },\n);\n\ninterface FrontMatter {\n description?: string;\n include?: string;\n globs?: string;\n}\n\nasync function parseMarkdownFile(filePath: string): Promise<{\n filename: string;\n description?: string;\n include?: string;\n}> {\n try {\n const content = await fs.readFile(filePath, \"utf-8\");\n const filename = path.basename(filePath);\n\n if (content.startsWith(\"---\")) {\n const parsed = matter(content);\n const frontMatter = parsed.data as FrontMatter;\n return {\n filename,\n description: frontMatter.description,\n include: frontMatter.include || frontMatter.globs,\n };\n }\n\n return { filename };\n } catch {\n return { filename: path.basename(filePath) };\n }\n}\n\nfunction formatPromptListItem(prompt: {\n filename: string;\n description?: string;\n include?: string;\n}): string {\n const { filename, description, include } = prompt;\n\n if (description && include) {\n return `* ${filename}: ${description} - Required for ${include}`;\n } else if (description) {\n return `* ${filename}: ${description}`;\n } else if (include) {\n return `* ${filename} - Required for ${include}`;\n } else {\n return `* ${filename}`;\n }\n}\n\nserver.tool(\n \"list_prompts\",\n \"Returns a bulleted list of all .md files in the prompts directory with their descriptions and requirements\",\n {},\n async () => {\n try {\n const files = await fs.readdir(PROMPTS_PATH);\n const mdFiles = files.filter((file) => file.endsWith(\".md\"));\n\n const prompts = await Promise.all(\n mdFiles.map((file) => parseMarkdownFile(path.join(PROMPTS_PATH, file))),\n );\n\n const formattedList = prompts.map(formatPromptListItem).join(\"\\n\");\n\n return {\n content: [\n {\n type: \"text\" as const,\n text:\n formattedList || \"No .md files found in the prompts directory.\",\n },\n ],\n };\n } catch (error) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error listing prompts: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n },\n ],\n };\n }\n },\n);\n\nserver.tool(\n \"read_prompt\",\n \"Returns the contents of a specified prompt file\",\n {\n filename: z\n .string()\n .describe(\n \"The name of the prompt file to read (e.g., example_prompt.md)\",\n ),\n },\n async ({ filename }) => {\n try {\n const filePath = path.join(PROMPTS_PATH, filename);\n const content = await fs.readFile(filePath, \"utf-8\");\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: content,\n },\n ],\n };\n } catch (error) {\n if ((error as { code?: string }).code === \"ENOENT\") {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error: Prompt file \"${filename}\" not found in prompts directory`,\n },\n ],\n };\n }\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error reading prompt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n },\n ],\n };\n }\n },\n);\n\nasync function main() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n // Server is running on stdio\n}\n\nmain();\n\nexport { server };\n"],"names":[],"mappings":";;;;;;;;;AAQA;AACA,MAAM,OAAO,GAAG,OAAO;AAEvB,MAAM,UAAU,GAAG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AAED,MAAM,CAAC,IAAI,CACT,aAAa,EACb,iDAAiD,EACjD;AACE,IAAA,QAAQ,EAAE;AACP,SAAA,MAAM;SACN,QAAQ,CACP,+DAA+D,CAChE;AACJ,CAAA,EACD,OAAO,EAAE,QAAQ,EAAE,KAAI;AACrB,IAAA,IAAI;QACF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC;QAClD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;QAEpD,OAAO;AACL,YAAA,OAAO,EAAE;AACP,gBAAA;AACE,oBAAA,IAAI,EAAE,MAAe;AACrB,oBAAA,IAAI,EAAE,OAAO;AACd,iBAAA;AACF,aAAA;SACF;IACH;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,IAAK,KAA2B,CAAC,IAAI,KAAK,QAAQ,EAAE;YAClD,OAAO;AACL,gBAAA,OAAO,EAAE;AACP,oBAAA;AACE,wBAAA,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,CAAA,oBAAA,EAAuB,QAAQ,CAAA,gCAAA,CAAkC;AACxE,qBAAA;AACF,iBAAA;aACF;QACH;QAEA,OAAO;AACL,YAAA,OAAO,EAAE;AACP,gBAAA;AACE,oBAAA,IAAI,EAAE,MAAe;AACrB,oBAAA,IAAI,EAAE,CAAA,2BAAA,EAA8B,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,eAAe,CAAA,CAAE;AAC/F,iBAAA;AACF,aAAA;SACF;IACH;AACF,CAAC,CACF;AAED,eAAe,IAAI,GAAA;AACjB,IAAA,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE;AAC5C,IAAA,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;;AAEjC;AAEA,IAAI,EAAE;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/createMcpServer.ts","../src/mcpExpressHandler.ts","../src/index.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport * as fs from \"fs/promises\";\nimport * as path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport matter from \"gray-matter\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst PROMPTS_PATH = path.join(__dirname, \"..\", \"prompts\");\n\ninterface FrontMatter {\n description?: string;\n include?: string;\n globs?: string;\n}\n\nasync function parseMarkdownFile(filePath: string): Promise<{\n filename: string;\n description?: string;\n include?: string;\n}> {\n try {\n const content = await fs.readFile(filePath, \"utf-8\");\n const filename = path.basename(filePath);\n\n if (content.startsWith(\"---\")) {\n const parsed = matter(content);\n const frontMatter = parsed.data as FrontMatter;\n return {\n filename,\n description: frontMatter.description,\n include: frontMatter.include || frontMatter.globs,\n };\n }\n\n return { filename };\n } catch {\n return { filename: path.basename(filePath) };\n }\n}\n\nfunction formatPromptListItem(prompt: {\n filename: string;\n description?: string;\n include?: string;\n}): string {\n const { filename, description, include } = prompt;\n\n if (description && include) {\n return `* ${filename}: ${description} - Required for ${include}`;\n } else if (description) {\n return `* ${filename}: ${description}`;\n } else if (include) {\n return `* ${filename} - Required for ${include}`;\n } else {\n return `* ${filename}`;\n }\n}\n\n/**\n * Creates and configures an MCP server instance with Jaypie tools\n * @param version - The version string for the server\n * @returns Configured MCP server instance\n */\nexport function createMcpServer(version: string = \"0.0.0\"): McpServer {\n const server = new McpServer(\n {\n name: \"jaypie\",\n version,\n },\n {\n capabilities: {},\n },\n );\n\n server.tool(\n \"list_prompts\",\n \"Returns a bulleted list of all .md files in the prompts directory with their descriptions and requirements\",\n {},\n async () => {\n try {\n const files = await fs.readdir(PROMPTS_PATH);\n const mdFiles = files.filter((file) => file.endsWith(\".md\"));\n\n const prompts = await Promise.all(\n mdFiles.map((file) =>\n parseMarkdownFile(path.join(PROMPTS_PATH, file)),\n ),\n );\n\n const formattedList = prompts.map(formatPromptListItem).join(\"\\n\");\n\n return {\n content: [\n {\n type: \"text\" as const,\n text:\n formattedList || \"No .md files found in the prompts directory.\",\n },\n ],\n };\n } catch (error) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error listing prompts: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n },\n ],\n };\n }\n },\n );\n\n server.tool(\n \"read_prompt\",\n \"Returns the contents of a specified prompt file\",\n {\n filename: z\n .string()\n .describe(\n \"The name of the prompt file to read (e.g., example_prompt.md)\",\n ),\n },\n async ({ filename }) => {\n try {\n const filePath = path.join(PROMPTS_PATH, filename);\n const content = await fs.readFile(filePath, \"utf-8\");\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: content,\n },\n ],\n };\n } catch (error) {\n if ((error as { code?: string }).code === \"ENOENT\") {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error: Prompt file \"${filename}\" not found in prompts directory`,\n },\n ],\n };\n }\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Error reading prompt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n },\n ],\n };\n }\n },\n );\n\n return server;\n}\n","import { Request, Response } from \"express\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { randomUUID } from \"crypto\";\nimport { createMcpServer } from \"./createMcpServer.js\";\n\n// Version will be injected during build\nconst DEFAULT_VERSION = \"0.0.0\";\n\n/**\n * Options for configuring the MCP Express handler\n */\nexport interface McpExpressHandlerOptions {\n /**\n * Version string for the MCP server\n */\n version?: string;\n /**\n * Whether to enable session management (stateful mode)\n * Default: true\n */\n enableSessions?: boolean;\n /**\n * Custom session ID generator function\n */\n sessionIdGenerator?: () => string;\n /**\n * Enable JSON responses instead of SSE streaming\n * Default: false\n */\n enableJsonResponse?: boolean;\n}\n\n/**\n * Creates an Express handler for the Jaypie MCP server using HTTP transport\n *\n * @param options - Configuration options for the handler\n * @returns Express middleware function\n *\n * @example\n * ```typescript\n * import express from 'express';\n * import { mcpExpressHandler } from '@jaypie/mcp';\n *\n * const app = express();\n * app.use(express.json());\n *\n * app.use('/mcp', mcpExpressHandler({\n * version: '1.0.0',\n * enableSessions: true\n * }));\n *\n * app.listen(3000, () => {\n * console.log('MCP server running on http://localhost:3000/mcp');\n * });\n * ```\n */\nexport function mcpExpressHandler(\n options: McpExpressHandlerOptions = {},\n): (req: Request, res: Response) => Promise<void> {\n const {\n version = DEFAULT_VERSION,\n enableSessions = true,\n sessionIdGenerator = () => randomUUID(),\n enableJsonResponse = false,\n } = options;\n\n const server = createMcpServer(version);\n\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: enableSessions ? sessionIdGenerator : undefined,\n enableJsonResponse,\n });\n\n server.connect(transport);\n\n return async (req: Request, res: Response): Promise<void> => {\n try {\n await transport.handleRequest(req, res, req.body);\n } catch (error) {\n if (!res.headersSent) {\n res.status(500).json({\n error: \"Internal server error\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n });\n }\n }\n };\n}\n","#!/usr/bin/env node\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createMcpServer } from \"./createMcpServer.js\";\n\n// Version will be injected during build\nconst version = \"0.0.0\";\n\nasync function main() {\n const server = createMcpServer(version);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n // Server is running on stdio\n}\n\nif (import.meta.url === `file://${process.argv[1]}`) {\n main();\n}\n\nexport { createMcpServer } from \"./createMcpServer.js\";\nexport {\n mcpExpressHandler,\n type McpExpressHandlerOptions,\n} from \"./mcpExpressHandler.js\";\n"],"names":[],"mappings":";;;;;;;;;;;AAOA,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AACjD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;AAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC;AAQ1D,eAAe,iBAAiB,CAAC,QAAgB,EAAA;AAK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,GAAG,IAAI,6BAA6B,CAAC;QAClD,kBAAkB,EAAE,cAAc,GAAG,kBAAkB,GAAG,SAAS;QACnE,kBAAkB;AACnB,KAAA,CAAC;AAEF,IAAA,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;AAEzB,IAAA,OAAO,OAAO,GAAY,EAAE,GAAa,KAAmB;AAC1D,QAAA,IAAI;AACF,YAAA,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC;QACnD;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;AACpB,gBAAA,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACnB,oBAAA,KAAK,EAAE,uBAAuB;AAC9B,oBAAA,OAAO,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,eAAe;AAClE,iBAAA,CAAC;YACJ;QACF;AACF,IAAA,CAAC;AACH;;ACnFA;AACA,MAAM,OAAO,GAAG,OAAO;AAEvB,eAAe,IAAI,GAAA;AACjB,IAAA,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC;AACvC,IAAA,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE;AAC5C,IAAA,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;;AAEjC;AAEA,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA,OAAA,EAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA,CAAE,EAAE;AACnD,IAAA,IAAI,EAAE;AACR;;;;"}
@@ -0,0 +1,49 @@
1
+ import { Request, Response } from "express";
2
+ /**
3
+ * Options for configuring the MCP Express handler
4
+ */
5
+ export interface McpExpressHandlerOptions {
6
+ /**
7
+ * Version string for the MCP server
8
+ */
9
+ version?: string;
10
+ /**
11
+ * Whether to enable session management (stateful mode)
12
+ * Default: true
13
+ */
14
+ enableSessions?: boolean;
15
+ /**
16
+ * Custom session ID generator function
17
+ */
18
+ sessionIdGenerator?: () => string;
19
+ /**
20
+ * Enable JSON responses instead of SSE streaming
21
+ * Default: false
22
+ */
23
+ enableJsonResponse?: boolean;
24
+ }
25
+ /**
26
+ * Creates an Express handler for the Jaypie MCP server using HTTP transport
27
+ *
28
+ * @param options - Configuration options for the handler
29
+ * @returns Express middleware function
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import express from 'express';
34
+ * import { mcpExpressHandler } from '@jaypie/mcp';
35
+ *
36
+ * const app = express();
37
+ * app.use(express.json());
38
+ *
39
+ * app.use('/mcp', mcpExpressHandler({
40
+ * version: '1.0.0',
41
+ * enableSessions: true
42
+ * }));
43
+ *
44
+ * app.listen(3000, () => {
45
+ * console.log('MCP server running on http://localhost:3000/mcp');
46
+ * });
47
+ * ```
48
+ */
49
+ export declare function mcpExpressHandler(options?: McpExpressHandlerOptions): (req: Request, res: Response) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/mcp",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Jaypie MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Finlayson Studio",
@@ -36,9 +36,12 @@
36
36
  "zod": "^3.23.8"
37
37
  },
38
38
  "devDependencies": {
39
+ "@types/express": "^5.0.3",
40
+ "express": "^5.1.0",
39
41
  "shx": "^0.3.4"
40
42
  },
41
43
  "publishConfig": {
42
44
  "access": "public"
43
- }
45
+ },
46
+ "gitHead": "cdfbc2d54bb745018c7147cc0bd694aae8614565"
44
47
  }