Skip to content

Commit 274d09f

Browse files
committed
feat: update version to 0.1.9; enhance test command permissions and refactor server creation logic
1 parent 51c89ab commit 274d09f

File tree

7 files changed

+275
-260
lines changed

7 files changed

+275
-260
lines changed

packages/core/deno.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@mcpc/core",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"tasks": {
55
"server:compile": "echo \"no need to compile\"",
6-
"test": "deno test --allow-env --allow-read tests/",
7-
"test:watch": "deno test --allow-env --allow-read --watch tests/"
6+
"test": "deno test --allow-all tests/",
7+
"test:watch": "deno test --allow-all --watch tests/"
88
},
99
"imports": {
1010
"@ai-sdk/openai": "npm:@ai-sdk/openai@^1.3.7",

packages/core/examples/01-basic-composition.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@
1313
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1414
import { mcpc } from "../mod.ts";
1515

16-
export const server = await mcpc(
17-
[
18-
{
19-
name: "basic-file-manager",
20-
version: "1.0.0",
21-
},
22-
{
23-
capabilities: {
24-
tools: {
25-
listChanged: true,
26-
},
27-
},
28-
},
29-
],
30-
[
31-
{
32-
name: "file-organizer",
33-
description:
34-
`I am a smart file organizer that helps users manage their files efficiently.
16+
export const toolDefinitions = [
17+
{
18+
name: "file-organizer",
19+
description:
20+
`I am a smart file organizer that helps users manage their files efficiently.
3521
3622
Available tools:
3723
<tool name="@wonderwhy-er/desktop-commander.list_directory"/>
@@ -50,17 +36,33 @@ I can:
5036
5137
I always ask for confirmation before making destructive changes and provide clear explanations of what I'm doing.`,
5238

53-
deps: {
54-
mcpServers: {
55-
"@wonderwhy-er/desktop-commander": {
56-
command: "npx",
57-
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
58-
transportType: "stdio",
59-
},
39+
deps: {
40+
mcpServers: {
41+
"@wonderwhy-er/desktop-commander": {
42+
command: "npx",
43+
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
44+
transportType: "stdio",
45+
},
46+
},
47+
},
48+
},
49+
];
50+
51+
export const server = await mcpc(
52+
[
53+
{
54+
name: "basic-file-manager",
55+
version: "1.0.0",
56+
},
57+
{
58+
capabilities: {
59+
tools: {
60+
listChanged: true,
6061
},
6162
},
6263
},
6364
],
65+
toolDefinitions,
6466
);
6567

6668
const transport = new StdioServerTransport();

packages/core/src/app.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { OpenAPIHono } from "@hono/zod-openapi";
22
import { registerAgent } from "./controllers/register.ts";
33
import { mcpc } from "./set-up-mcp-compose.ts";
4-
import { toolDefinitions } from "../examples/sampling/01-basic-composition.ts";
4+
import { toolDefinitions } from "../examples/01-basic-composition.ts";
55

6-
export const server = await mcpc([
7-
{
8-
name: "capi-mcp",
9-
version: "0.1.0",
10-
},
11-
{ capabilities: { tools: {}, sampling: {} } },
12-
], toolDefinitions);
6+
export const createServer = async () =>
7+
await mcpc(
8+
[
9+
{
10+
name: "capi-mcp",
11+
version: "0.1.0",
12+
},
13+
{ capabilities: { tools: {}, sampling: {} } },
14+
],
15+
toolDefinitions,
16+
);
1317

1418
export const createApp = () => {
1519
const app = new OpenAPIHono();

packages/core/src/controllers/sse.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRoute, type OpenAPIHono, z } from "@hono/zod-openapi";
22
import type { ErrorSchema as _ErrorSchema } from "../schemas/error.ts";
3-
import { server } from "../app.ts";
3+
import { createServer } from "../app.ts";
44
import { INCOMING_MSG_ROUTE_PATH } from "../set-up-mcp-compose.ts";
55
import { handleConnecting } from "../transport/sse.ts";
66

@@ -32,7 +32,7 @@ export const sseHandler = (app: OpenAPIHono) =>
3232
async (c) => {
3333
const response = await handleConnecting(
3434
c.req.raw,
35-
server,
35+
createServer,
3636
INCOMING_MSG_ROUTE_PATH,
3737
);
3838
return response;

packages/core/src/transport/sse.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import type { ComposableMCPServer } from "../../mod.ts";
2222
*/
2323
const transports = new Map<string, SSEServerTransport>();
2424

25-
export function handleConnecting(
25+
export async function handleConnecting(
2626
request: Request,
27-
server: McpServer | ComposableMCPServer,
27+
createServer: () => Promise<McpServer | ComposableMCPServer>,
2828
incomingMsgRoutePath: string,
2929
): Promise<Response> {
3030
// Check if a session ID is provided in the request
@@ -48,6 +48,8 @@ export function handleConnecting(
4848
}
4949
}
5050

51+
const server = await createServer();
52+
5153
// Create a new transport with the endpoint if no session ID was provided
5254
const transport = new SSEServerTransport(endpoint);
5355
const newSessionId = transport.sessionId;

0 commit comments

Comments
 (0)