Skip to content

Commit f6b87cb

Browse files
ochafikclaude
andcommitted
feat: add server helpers and optional connect() transport
Add `src/server/` with convenience functions for registering MCP App tools and resources: - `registerAppTool(server, name, config, handler)` - `registerAppResource(server, name, uri, config, callback)` The `transport` parameter in `App.connect()` is now optional, defaulting to `PostMessageTransport(window.parent)`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 31e05d3 commit f6b87cb

File tree

14 files changed

+348
-16
lines changed

14 files changed

+348
-16
lines changed

examples/basic-server-react/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
33
import type { CallToolResult, ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
44
import fs from "node:fs/promises";
55
import path from "node:path";
6-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
6+
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps/server";
77
import { startServer } from "../shared/server-utils.js";
88

99
const DIST_DIR = path.join(import.meta.dirname, "dist");
@@ -22,7 +22,7 @@ function createServer(): McpServer {
2222
// MCP Apps require two-part registration: a tool (what the LLM calls) and a
2323
// resource (the UI it renders). The `_meta` field on the tool links to the
2424
// resource URI, telling hosts which UI to display when the tool executes.
25-
server.registerTool(
25+
registerAppTool(server,
2626
"get-time",
2727
{
2828
title: "Get Time",
@@ -38,7 +38,7 @@ function createServer(): McpServer {
3838
},
3939
);
4040

41-
server.registerResource(
41+
registerAppResource(server,
4242
RESOURCE_URI,
4343
RESOURCE_URI,
4444
{ mimeType: RESOURCE_MIME_TYPE },

examples/basic-server-vanillajs/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
33
import type { CallToolResult, ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
44
import fs from "node:fs/promises";
55
import path from "node:path";
6-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
6+
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps/server";
77
import { startServer } from "../shared/server-utils.js";
88

99
const DIST_DIR = path.join(import.meta.dirname, "dist");
@@ -22,7 +22,7 @@ function createServer(): McpServer {
2222
// MCP Apps require two-part registration: a tool (what the LLM calls) and a
2323
// resource (the UI it renders). The `_meta` field on the tool links to the
2424
// resource URI, telling hosts which UI to display when the tool executes.
25-
server.registerTool(
25+
registerAppTool(server,
2626
"get-time",
2727
{
2828
title: "Get Time",
@@ -38,7 +38,7 @@ function createServer(): McpServer {
3838
},
3939
);
4040

41-
server.registerResource(
41+
registerAppResource(server,
4242
RESOURCE_URI,
4343
RESOURCE_URI,
4444
{ mimeType: RESOURCE_MIME_TYPE },

examples/basic-server-vanillajs/src/mcp-app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file App that demonstrates a few features using MCP Apps SDK with vanilla JS.
33
*/
4-
import { App, PostMessageTransport } from "@modelcontextprotocol/ext-apps";
4+
import { App } from "@modelcontextprotocol/ext-apps";
55
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
66
import "./global.css";
77
import "./mcp-app.css";
@@ -98,4 +98,4 @@ openLinkBtn.addEventListener("click", async () => {
9898

9999

100100
// Connect to host
101-
app.connect(new PostMessageTransport(window.parent));
101+
app.connect();

examples/budget-allocator-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
import fs from "node:fs/promises";
1414
import path from "node:path";
1515
import { z } from "zod";
16-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
16+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1717
import { startServer } from "../shared/server-utils.js";
1818

1919
const DIST_DIR = path.join(import.meta.dirname, "dist");

examples/cohort-heatmap-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
44
import fs from "node:fs/promises";
55
import path from "node:path";
66
import { z } from "zod";
7-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
7+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
88
import { startServer } from "../shared/server-utils.js";
99

1010
const DIST_DIR = path.join(import.meta.dirname, "dist");

examples/customer-segmentation-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import fs from "node:fs/promises";
88
import path from "node:path";
99
import { z } from "zod";
10-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
10+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1111
import { startServer } from "../shared/server-utils.js";
1212
import {
1313
generateCustomers,

examples/scenario-modeler-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import fs from "node:fs/promises";
88
import path from "node:path";
99
import { z } from "zod";
10-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
10+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1111
import { startServer } from "../shared/server-utils.js";
1212

1313
const DIST_DIR = path.join(import.meta.dirname, "dist");

examples/system-monitor-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import os from "node:os";
99
import path from "node:path";
1010
import si from "systeminformation";
1111
import { z } from "zod";
12-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
12+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1313
import { startServer } from "../shared/server-utils.js";
1414

1515
// Schemas - types are derived from these using z.infer

examples/threejs-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
99
import fs from "node:fs/promises";
1010
import path from "node:path";
1111
import { z } from "zod";
12-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
12+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1313
import { startServer } from "../shared/server-utils.js";
1414

1515
const DIST_DIR = path.join(import.meta.dirname, "dist");

examples/wiki-explorer-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as cheerio from "cheerio";
88
import fs from "node:fs/promises";
99
import path from "node:path";
1010
import { z } from "zod";
11-
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "../../dist/src/app";
11+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
1212
import { startServer } from "../shared/server-utils.js";
1313

1414
const DIST_DIR = path.join(import.meta.dirname, "dist");

0 commit comments

Comments
 (0)