plugmcp 0.0.0-stage → 0.1.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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +232 -2
  3. package/dist/agent.d.ts +20 -0
  4. package/dist/agent.js +35 -0
  5. package/dist/build.d.ts +13 -0
  6. package/dist/build.js +83 -0
  7. package/dist/cli/cloud.d.ts +20 -0
  8. package/dist/cli/cloud.js +56 -0
  9. package/dist/cli/index.d.ts +2 -0
  10. package/dist/cli/index.js +326 -0
  11. package/dist/dev/api.d.ts +37 -0
  12. package/dist/dev/api.js +788 -0
  13. package/dist/dev/chat.d.ts +63 -0
  14. package/dist/dev/chat.js +159 -0
  15. package/dist/dev/dev.d.ts +22 -0
  16. package/dist/dev/dev.js +188 -0
  17. package/dist/dev/edit.d.ts +22 -0
  18. package/dist/dev/edit.js +147 -0
  19. package/dist/dev/generate.d.ts +21 -0
  20. package/dist/dev/generate.js +97 -0
  21. package/dist/dev/keys.d.ts +61 -0
  22. package/dist/dev/keys.js +55 -0
  23. package/dist/dev/project.d.ts +26 -0
  24. package/dist/dev/project.js +68 -0
  25. package/dist/dev/store.d.ts +61 -0
  26. package/dist/dev/store.js +113 -0
  27. package/dist/dev/views.d.ts +9 -0
  28. package/dist/dev/views.js +54 -0
  29. package/dist/http.d.ts +33 -0
  30. package/dist/http.js +79 -0
  31. package/dist/index.d.ts +77 -0
  32. package/dist/index.js +118 -0
  33. package/dist/install.d.ts +13 -0
  34. package/dist/install.js +54 -0
  35. package/dist/landing.d.ts +3 -0
  36. package/dist/landing.js +62 -0
  37. package/dist/stdio.d.ts +3 -0
  38. package/dist/stdio.js +5 -0
  39. package/dist/view/index.d.ts +34 -0
  40. package/dist/view/index.js +90 -0
  41. package/package.json +114 -4
  42. package/studio-dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  43. package/studio-dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  44. package/studio-dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  45. package/studio-dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  46. package/studio-dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  47. package/studio-dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  48. package/studio-dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  49. package/studio-dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  50. package/studio-dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  51. package/studio-dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  52. package/studio-dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  53. package/studio-dist/assets/index-BSR7LH_V.css +1 -0
  54. package/studio-dist/assets/index-D_yIYje_.js +137 -0
  55. package/studio-dist/index.html +15 -0
@@ -0,0 +1,77 @@
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
+ import type { CallToolResult, ToolAnnotations } from "@modelcontextprotocol/server";
3
+ import type { z } from "zod";
4
+ /** Mime type MCP Apps hosts expect for a UI resource. */
5
+ export declare const VIEW_MIME_TYPE = "text/html;profile=mcp-app";
6
+ declare const MARK: unique symbol;
7
+ export interface ViewCsp {
8
+ connectDomains?: string[];
9
+ resourceDomains?: string[];
10
+ frameDomains?: string[];
11
+ baseUriDomains?: string[];
12
+ }
13
+ export interface ViewOptions {
14
+ /** Domains the view may reach. Omit for a view that only talks to its host. */
15
+ csp?: ViewCsp;
16
+ /** Ask the host to draw a border around the view. */
17
+ prefersBorder?: boolean;
18
+ }
19
+ type Schema = z.ZodType;
20
+ type Infer<S> = S extends Schema ? z.infer<S> : Record<string, never>;
21
+ export interface ToolConfig<I extends Schema | undefined = undefined, O extends Schema | undefined = undefined> {
22
+ name: string;
23
+ title?: string;
24
+ description?: string;
25
+ /** Zod object schema for the arguments. The handler input is typed from it. */
26
+ input?: I;
27
+ /** Optional Zod object schema for the structured result. */
28
+ output?: O;
29
+ annotations?: ToolAnnotations;
30
+ /** Options for the view at `views/<name>.tsx`, or `false` to ignore that file. */
31
+ view?: ViewOptions | false;
32
+ }
33
+ export type ToolResult = string | CallToolResult | Record<string, unknown> | unknown[] | number | boolean | null | undefined | void;
34
+ export type ToolHandler<I extends Schema | undefined> = (input: Infer<I>, ctx: unknown) => ToolResult | Promise<ToolResult>;
35
+ export interface RegisteredTool {
36
+ config: ToolConfig<Schema | undefined, Schema | undefined>;
37
+ handler: (input: unknown, ctx: unknown) => ToolResult | Promise<ToolResult>;
38
+ }
39
+ export interface ServerInfo {
40
+ name: string;
41
+ version?: string;
42
+ title?: string;
43
+ description?: string;
44
+ /** Instructions sent to the model when a client connects. */
45
+ instructions?: string;
46
+ websiteUrl?: string;
47
+ }
48
+ /** HTML for one view, supplied by `plugmcp dev` or `plugmcp start`. */
49
+ export interface ViewSource {
50
+ html: () => string | Promise<string>;
51
+ csp?: ViewCsp;
52
+ }
53
+ export interface BuildOptions {
54
+ views?: Record<string, ViewSource>;
55
+ }
56
+ export declare function slugify(value: string): string;
57
+ export declare function viewUri(serverName: string, toolName: string): string;
58
+ /** Turn whatever a handler returned into an MCP tool result. */
59
+ export declare function toToolResult(value: ToolResult): CallToolResult;
60
+ export declare class PlugServer {
61
+ readonly [MARK] = true;
62
+ readonly info: ServerInfo;
63
+ readonly tools: Map<string, RegisteredTool>;
64
+ private extenders;
65
+ constructor(info: ServerInfo);
66
+ /** Add a tool. Return a string, a plain object, or a full MCP result. */
67
+ tool<I extends Schema | undefined = undefined, O extends Schema | undefined = undefined>(config: ToolConfig<I, O>, handler: ToolHandler<I>): this;
68
+ /** Escape hatch: register prompts, resources or anything else on the underlying McpServer. */
69
+ extend(fn: (server: McpServer) => void): this;
70
+ /** Create a fresh McpServer. Called once per HTTP request or stdio connection. */
71
+ build(options?: BuildOptions): McpServer;
72
+ }
73
+ export declare function createServer(info: ServerInfo): PlugServer;
74
+ export declare function isPlugServer(value: unknown): value is PlugServer;
75
+ export { serveHttp, createHttpHandler, type ServeHttpOptions, type RunningServer } from "./http.js";
76
+ export { serveStdio } from "./stdio.js";
77
+ export type { CallToolResult, ToolAnnotations, McpServer };
package/dist/index.js ADDED
@@ -0,0 +1,118 @@
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
+ /** Mime type MCP Apps hosts expect for a UI resource. */
3
+ export const VIEW_MIME_TYPE = "text/html;profile=mcp-app";
4
+ const MARK = Symbol.for("plugmcp.server");
5
+ const CALLS = Symbol.for("plugmcp.calls");
6
+ export function slugify(value) {
7
+ return (value
8
+ .toLowerCase()
9
+ .replace(/[^a-z0-9]+/g, "-")
10
+ .replace(/^-+|-+$/g, "") || "server");
11
+ }
12
+ export function viewUri(serverName, toolName) {
13
+ return `ui://${slugify(serverName)}/${toolName}.html`;
14
+ }
15
+ /** Turn whatever a handler returned into an MCP tool result. */
16
+ export function toToolResult(value) {
17
+ if (typeof value === "string")
18
+ return { content: [{ type: "text", text: value }] };
19
+ if (value === undefined || value === null)
20
+ return { content: [{ type: "text", text: "Done." }] };
21
+ if (typeof value === "object" && !Array.isArray(value) && Array.isArray(value.content)) {
22
+ return value;
23
+ }
24
+ const structured = typeof value === "object" && !Array.isArray(value) ? value : { result: value };
25
+ return { content: [{ type: "text", text: JSON.stringify(structured, null, 2) }], structuredContent: structured };
26
+ }
27
+ export class PlugServer {
28
+ [MARK] = true;
29
+ info;
30
+ tools = new Map();
31
+ extenders = [];
32
+ constructor(info) {
33
+ this.info = info;
34
+ }
35
+ /** Add a tool. Return a string, a plain object, or a full MCP result. */
36
+ tool(config, handler) {
37
+ if (!/^[A-Za-z0-9_.-]{1,64}$/.test(config.name)) {
38
+ throw new Error(`Tool name "${config.name}" must be 1-64 characters of letters, numbers, "_", "-" or ".".`);
39
+ }
40
+ if (this.tools.has(config.name))
41
+ throw new Error(`Tool "${config.name}" is defined twice.`);
42
+ this.tools.set(config.name, {
43
+ config: config,
44
+ handler: handler,
45
+ });
46
+ return this;
47
+ }
48
+ /** Escape hatch: register prompts, resources or anything else on the underlying McpServer. */
49
+ extend(fn) {
50
+ this.extenders.push(fn);
51
+ return this;
52
+ }
53
+ /** Create a fresh McpServer. Called once per HTTP request or stdio connection. */
54
+ build(options = {}) {
55
+ const { name, version = "0.1.0", title, description, websiteUrl, instructions } = this.info;
56
+ const server = new McpServer({
57
+ name,
58
+ version,
59
+ ...(title ? { title } : {}),
60
+ ...(description ? { description } : {}),
61
+ ...(websiteUrl ? { websiteUrl } : {}),
62
+ }, instructions ? { instructions } : undefined);
63
+ for (const { config, handler } of this.tools.values()) {
64
+ const view = config.view === false ? undefined : options.views?.[config.name];
65
+ const viewOptions = config.view === false ? undefined : config.view;
66
+ const uri = view ? viewUri(name, config.name) : undefined;
67
+ const csp = viewOptions?.csp ?? view?.csp;
68
+ if (view && uri) {
69
+ const uiMeta = {
70
+ ...(csp ? { csp } : {}),
71
+ ...(viewOptions?.prefersBorder !== undefined ? { prefersBorder: viewOptions.prefersBorder } : {}),
72
+ };
73
+ server.registerResource(`${config.name}-view`, uri, { title: `${config.title ?? config.name} view`, mimeType: VIEW_MIME_TYPE }, async () => ({
74
+ contents: [{ uri, mimeType: VIEW_MIME_TYPE, text: await view.html(), _meta: { ui: uiMeta } }],
75
+ }));
76
+ }
77
+ const tool = {
78
+ ...(config.title ? { title: config.title } : {}),
79
+ ...(config.description ? { description: config.description } : {}),
80
+ ...(config.input ? { inputSchema: config.input } : {}),
81
+ ...(config.output ? { outputSchema: config.output } : {}),
82
+ ...(config.annotations ? { annotations: config.annotations } : {}),
83
+ ...(uri ? { _meta: { ui: { resourceUri: uri }, "openai/outputTemplate": uri } } : {}),
84
+ };
85
+ const run = async (input, ctx) => {
86
+ const started = performance.now();
87
+ let result;
88
+ try {
89
+ result = toToolResult(await handler(input, ctx));
90
+ }
91
+ catch (error) {
92
+ const message = error instanceof Error ? error.message : String(error);
93
+ result = { content: [{ type: "text", text: message }], isError: true };
94
+ }
95
+ // `plugmcp dev` listens here to show calls in the Studio. Nothing listens in production.
96
+ const report = globalThis[CALLS];
97
+ report?.({ server: this.info.name, tool: config.name, input, ms: Math.round(performance.now() - started), result });
98
+ return result;
99
+ };
100
+ // The SDK passes the context alone when a tool has no input schema.
101
+ const callback = config.input ? run : (ctx) => run({}, ctx);
102
+ server.registerTool(config.name, tool, callback);
103
+ }
104
+ for (const fn of this.extenders)
105
+ fn(server);
106
+ return server;
107
+ }
108
+ }
109
+ export function createServer(info) {
110
+ if (!info?.name)
111
+ throw new Error("createServer needs a name.");
112
+ return new PlugServer(info);
113
+ }
114
+ export function isPlugServer(value) {
115
+ return typeof value === "object" && value !== null && value[MARK] === true;
116
+ }
117
+ export { serveHttp, createHttpHandler } from "./http.js";
118
+ export { serveStdio } from "./stdio.js";
@@ -0,0 +1,13 @@
1
+ /** Install snippets for the common MCP clients, for a server reachable at a URL. */
2
+ export interface InstallSnippet {
3
+ id: string;
4
+ label: string;
5
+ kind: "link" | "code";
6
+ value: string;
7
+ hint?: string;
8
+ }
9
+ export declare function installSnippets(name: string, url: string): InstallSnippet[];
10
+ export declare const DIRECTORY_URL = "https://plugmcp.ai";
11
+ export declare function directoryPage(slug: string): string;
12
+ /** Markdown badge for a README. The link is the useful part; the image is a plain shields.io badge. */
13
+ export declare function readmeBadge(slug: string): string;
@@ -0,0 +1,54 @@
1
+ /** Install snippets for the common MCP clients, for a server reachable at a URL. */
2
+ const base64 = (text) => Buffer.from(text, "utf8").toString("base64");
3
+ export function installSnippets(name, url) {
4
+ const json = JSON.stringify({ mcpServers: { [name]: { url } } }, null, 2);
5
+ return [
6
+ {
7
+ id: "cursor",
8
+ label: "Cursor",
9
+ kind: "link",
10
+ value: `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(name)}&config=${encodeURIComponent(base64(JSON.stringify({ url })))}`,
11
+ },
12
+ {
13
+ id: "vscode",
14
+ label: "VS Code",
15
+ kind: "link",
16
+ value: `vscode:mcp/install?${encodeURIComponent(JSON.stringify({ name, type: "http", url }))}`,
17
+ },
18
+ {
19
+ id: "claude-code",
20
+ label: "Claude Code",
21
+ kind: "code",
22
+ value: `claude mcp add --transport http ${name} ${url}`,
23
+ },
24
+ {
25
+ id: "codex",
26
+ label: "Codex",
27
+ kind: "code",
28
+ value: `codex mcp add ${name} --url ${url}`,
29
+ },
30
+ {
31
+ id: "claude",
32
+ label: "Claude",
33
+ kind: "code",
34
+ value: url,
35
+ hint: "Settings, Connectors, Add custom connector, then paste this address. It must be a public https address.",
36
+ },
37
+ {
38
+ id: "chatgpt",
39
+ label: "ChatGPT",
40
+ kind: "code",
41
+ value: url,
42
+ hint: "Settings, Apps and Connectors, Create, then paste this address. It must be a public https address.",
43
+ },
44
+ { id: "json", label: "JSON", kind: "code", value: json, hint: "For any client that reads an mcpServers block." },
45
+ ];
46
+ }
47
+ export const DIRECTORY_URL = "https://plugmcp.ai";
48
+ export function directoryPage(slug) {
49
+ return `${DIRECTORY_URL}/mcp/${slug}`;
50
+ }
51
+ /** Markdown badge for a README. The link is the useful part; the image is a plain shields.io badge. */
52
+ export function readmeBadge(slug) {
53
+ return `[![Listed on PlugMCP](https://img.shields.io/badge/listed%20on-PlugMCP-0099FF)](${directoryPage(slug)})`;
54
+ }
@@ -0,0 +1,3 @@
1
+ import type { PlugServer } from "./index.js";
2
+ /** The page a person sees when they open the MCP address in a browser. */
3
+ export declare function landingPage(server: PlugServer, url: string): string;
@@ -0,0 +1,62 @@
1
+ import { DIRECTORY_URL, installSnippets } from "./install.js";
2
+ const esc = (text) => text.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
3
+ /** The page a person sees when they open the MCP address in a browser. */
4
+ export function landingPage(server, url) {
5
+ const { name, title, description } = server.info;
6
+ const tools = [...server.tools.values()];
7
+ const snippets = installSnippets(name, url);
8
+ const links = snippets
9
+ .filter((s) => s.kind === "link")
10
+ .map((s) => `<a class="btn" href="${esc(s.value)}">Add to ${esc(s.label)}</a>`)
11
+ .join("");
12
+ const code = snippets
13
+ .filter((s) => s.kind === "code")
14
+ .map((s) => `<section><h3>${esc(s.label)}</h3>${s.hint ? `<p class="muted">${esc(s.hint)}</p>` : ""}<pre>${esc(s.value)}</pre></section>`)
15
+ .join("");
16
+ const toolRows = tools
17
+ .map(({ config }) => `<li><code>${esc(config.name)}</code><span>${esc(config.description ?? config.title ?? "")}</span></li>`)
18
+ .join("");
19
+ return `<!doctype html>
20
+ <html lang="en">
21
+ <head>
22
+ <meta charset="utf-8">
23
+ <meta name="viewport" content="width=device-width, initial-scale=1">
24
+ <title>${esc(title ?? name)} - MCP server</title>
25
+ <meta name="description" content="${esc(description ?? `${name} is an MCP server with ${tools.length} tools.`)}">
26
+ <style>
27
+ :root{color-scheme:dark}
28
+ *{box-sizing:border-box}
29
+ body{margin:0;background:#0A0A0A;color:#F2EFE9;font:15px/1.6 Geist,ui-sans-serif,system-ui,sans-serif}
30
+ main{max-width:720px;margin:0 auto;padding:56px 16px 80px}
31
+ h1{font-size:30px;font-weight:500;margin:0 0 8px;letter-spacing:-.01em}
32
+ h2{font-size:17px;font-weight:500;margin:40px 0 12px}
33
+ h3{font-size:14px;font-weight:500;margin:20px 0 4px}
34
+ p{margin:0 0 12px}.muted{color:#8D8984}
35
+ .url{font:13px/1.5 "Geist Mono",ui-monospace,monospace;background:#121212;border:1px solid #222;border-radius:10px;padding:12px 14px;overflow-x:auto;white-space:nowrap}
36
+ .row{display:flex;flex-wrap:wrap;gap:8px;margin-top:16px}
37
+ .btn{display:inline-block;padding:9px 14px;border-radius:10px;background:#F2EFE9;color:#0A0A0A;text-decoration:none;font-weight:500;font-size:14px}
38
+ ul{list-style:none;padding:0;margin:0;border:1px solid #222;border-radius:10px}
39
+ li{display:flex;gap:12px;padding:10px 14px;border-top:1px solid #222;flex-wrap:wrap}
40
+ li:first-child{border-top:0}
41
+ code{font:13px "Geist Mono",ui-monospace,monospace;color:#3DB2FF}
42
+ li span{color:#C4C0B9}
43
+ pre{font:13px/1.5 "Geist Mono",ui-monospace,monospace;background:#121212;border:1px solid #222;border-radius:10px;padding:12px 14px;overflow-x:auto;margin:6px 0 0}
44
+ footer{margin-top:56px;padding-top:20px;border-top:1px solid #222;color:#8D8984;font-size:13px}
45
+ footer a{color:#C4C0B9}
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <main>
50
+ <h1>${esc(title ?? name)}</h1>
51
+ <p class="muted">${esc(description ?? "An MCP server. Connect it to an AI client to use its tools.")}</p>
52
+ <div class="url">${esc(url)}</div>
53
+ <div class="row">${links}</div>
54
+ <h2>Tools</h2>
55
+ ${tools.length ? `<ul>${toolRows}</ul>` : `<p class="muted">This server has no tools yet.</p>`}
56
+ <h2>Connect</h2>
57
+ ${code}
58
+ <footer>Built with the <a href="https://github.com/plugmcp-ai/plugmcp-framework">PlugMCP Framework</a>. Find more servers in the <a href="${DIRECTORY_URL}/mcp">PlugMCP directory</a>.</footer>
59
+ </main>
60
+ </body>
61
+ </html>`;
62
+ }
@@ -0,0 +1,3 @@
1
+ import type { BuildOptions, PlugServer } from "./index.js";
2
+ /** Serve over stdin and stdout, for clients that launch the server as a command. */
3
+ export declare function serveStdio(server: PlugServer, options?: BuildOptions): import("@modelcontextprotocol/server/stdio").StdioServerHandle;
package/dist/stdio.js ADDED
@@ -0,0 +1,5 @@
1
+ import { serveStdio as sdkServeStdio } from "@modelcontextprotocol/server/stdio";
2
+ /** Serve over stdin and stdout, for clients that launch the server as a command. */
3
+ export function serveStdio(server, options = {}) {
4
+ return sdkServeStdio(() => server.build(options));
5
+ }
@@ -0,0 +1,34 @@
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ import type { ReactNode } from "react";
3
+ /** Connects the view to its host. `plugmcp` wraps every view in this for you. */
4
+ export declare function ViewRoot({ name, children }: {
5
+ name: string;
6
+ children: ReactNode;
7
+ }): import("react").JSX.Element;
8
+ export interface CallResult<T = Record<string, unknown>> {
9
+ output: T | undefined;
10
+ text: string;
11
+ isError: boolean;
12
+ }
13
+ export interface ToolView<Output, Input> {
14
+ /** Arguments the model called the tool with. */
15
+ input: Input | undefined;
16
+ /** The object your handler returned. */
17
+ output: Output | undefined;
18
+ /** The text part of the result. */
19
+ text: string;
20
+ /** True until the tool result arrives. */
21
+ isPending: boolean;
22
+ isError: boolean;
23
+ theme: "light" | "dark";
24
+ /** Call any tool on this server from the view. */
25
+ callTool: <T = Record<string, unknown>>(name: string, args?: Record<string, unknown>) => Promise<CallResult<T>>;
26
+ /** Send a message into the conversation as the user. */
27
+ sendMessage: (text: string) => Promise<void>;
28
+ /** Ask the host to open a link. */
29
+ openLink: (url: string) => Promise<void>;
30
+ /** The underlying MCP Apps connection, for anything not covered here. */
31
+ app: App | null;
32
+ }
33
+ /** Read the tool call that opened this view, and talk back to the host. */
34
+ export declare function useTool<Output = Record<string, unknown>, Input = Record<string, unknown>>(): ToolView<Output, Input>;
@@ -0,0 +1,90 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { App } from "@modelcontextprotocol/ext-apps";
3
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
4
+ const ViewContext = createContext(null);
5
+ const textOf = (result) => (result?.content ?? [])
6
+ .filter((block) => block.type === "text" && typeof block.text === "string")
7
+ .map((block) => block.text)
8
+ .join("\n");
9
+ function applyTheme(host) {
10
+ const theme = host?.theme;
11
+ if (!theme)
12
+ return;
13
+ const root = document.documentElement;
14
+ root.dataset.theme = theme;
15
+ root.style.colorScheme = theme;
16
+ const variables = host?.styles?.variables;
17
+ for (const [key, value] of Object.entries(variables ?? {})) {
18
+ if (value)
19
+ root.style.setProperty(key, value);
20
+ }
21
+ }
22
+ /** Connects the view to its host. `plugmcp` wraps every view in this for you. */
23
+ export function ViewRoot({ name, children }) {
24
+ const [state, setState] = useState({
25
+ app: null,
26
+ connected: false,
27
+ error: null,
28
+ input: undefined,
29
+ result: undefined,
30
+ host: undefined,
31
+ });
32
+ useEffect(() => {
33
+ const app = new App({ name, version: "1.0.0" }, {}, { autoResize: true });
34
+ let alive = true;
35
+ const patch = (next) => alive && setState((prev) => ({ ...prev, ...next }));
36
+ app.ontoolinput = (params) => patch({ input: params.arguments ?? {}, result: undefined });
37
+ app.ontoolresult = (params) => patch({ result: params });
38
+ app.onhostcontextchanged = (params) => {
39
+ const host = { ...app.getHostContext(), ...params };
40
+ applyTheme(host);
41
+ patch({ host });
42
+ };
43
+ app
44
+ .connect()
45
+ .then(() => {
46
+ const host = app.getHostContext();
47
+ applyTheme(host);
48
+ patch({ app, connected: true, host });
49
+ })
50
+ .catch((error) => patch({ error: error instanceof Error ? error : new Error(String(error)) }));
51
+ return () => {
52
+ alive = false;
53
+ void app.close();
54
+ };
55
+ }, [name]);
56
+ return _jsx(ViewContext.Provider, { value: state, children: children });
57
+ }
58
+ /** Read the tool call that opened this view, and talk back to the host. */
59
+ export function useTool() {
60
+ const state = useContext(ViewContext);
61
+ if (!state)
62
+ throw new Error("useTool must be used inside a view rendered by plugmcp.");
63
+ const { app, input, result, host } = state;
64
+ return useMemo(() => {
65
+ const need = () => {
66
+ if (!app)
67
+ throw new Error("The view is not connected to a host yet.");
68
+ return app;
69
+ };
70
+ return {
71
+ input: input,
72
+ output: result?.structuredContent,
73
+ text: textOf(result),
74
+ isPending: result === undefined,
75
+ isError: result?.isError === true,
76
+ theme: host?.theme === "light" ? "light" : "dark",
77
+ callTool: async (name, args = {}) => {
78
+ const next = (await need().callServerTool({ name, arguments: args }));
79
+ return { output: next.structuredContent, text: textOf(next), isError: next.isError === true };
80
+ },
81
+ sendMessage: async (text) => {
82
+ await need().sendMessage({ role: "user", content: [{ type: "text", text }] });
83
+ },
84
+ openLink: async (url) => {
85
+ await need().openLink({ url });
86
+ },
87
+ app,
88
+ };
89
+ }, [app, input, result, host]);
90
+ }
package/package.json CHANGED
@@ -1,6 +1,116 @@
1
1
  {
2
2
  "name": "plugmcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "The framework for building MCP servers and MCP apps. Local Studio with a canvas, schema-first tool testing, a chat that builds tools with your own key, and the PlugMCP directory built in.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "homepage": "https://plugmcp.ai",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/plugmcp-ai/plugmcp-framework.git",
11
+ "directory": "packages/plugmcp"
12
+ },
13
+ "keywords": [
14
+ "mcp",
15
+ "model-context-protocol",
16
+ "mcp-server",
17
+ "mcp-framework",
18
+ "mcp-sdk",
19
+ "mcp-apps",
20
+ "mcp-ui",
21
+ "mcp-inspector",
22
+ "mcp-testing",
23
+ "mcp-tools",
24
+ "ai-agents",
25
+ "tool-calling",
26
+ "claude",
27
+ "chatgpt",
28
+ "cursor",
29
+ "openai",
30
+ "anthropic",
31
+ "llm",
32
+ "agent",
33
+ "ai",
34
+ "sdk",
35
+ "cli",
36
+ "typescript"
37
+ ],
38
+ "engines": {
39
+ "node": ">=20.19"
40
+ },
41
+ "bin": {
42
+ "plugmcp": "dist/cli/index.js"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "studio-dist",
47
+ "README.md",
48
+ "LICENSE"
49
+ ],
50
+ "exports": {
51
+ ".": {
52
+ "types": "./dist/index.d.ts",
53
+ "default": "./dist/index.js"
54
+ },
55
+ "./view": {
56
+ "types": "./dist/view/index.d.ts",
57
+ "default": "./dist/view/index.js"
58
+ },
59
+ "./agent": {
60
+ "types": "./dist/agent.d.ts",
61
+ "default": "./dist/agent.js"
62
+ },
63
+ "./package.json": "./package.json"
64
+ },
65
+ "scripts": {
66
+ "build": "tsc -p tsconfig.json",
67
+ "typecheck": "tsc -p tsconfig.json --noEmit",
68
+ "test": "vitest run",
69
+ "lint": "tsc -p tsconfig.json --noEmit",
70
+ "prepack": "node -e \"const fs=require('fs');fs.copyFileSync('../../README.md','README.md');fs.copyFileSync('../../LICENSE','LICENSE')\""
71
+ },
72
+ "dependencies": {
73
+ "@ai-sdk/anthropic": "^4.0.106",
74
+ "@ai-sdk/google": "^4.0.122",
75
+ "@ai-sdk/openai": "^4.0.121",
76
+ "@ai-sdk/openai-compatible": "^3.0.93",
77
+ "@modelcontextprotocol/client": "^2.4.0",
78
+ "@modelcontextprotocol/ext-apps": "^2.0.4",
79
+ "@modelcontextprotocol/node": "^2.1.2",
80
+ "@modelcontextprotocol/server": "^2.4.0",
81
+ "@vitejs/plugin-react": "^6.3.0",
82
+ "ai": "^7.0.177",
83
+ "vite": "^8.3.8",
84
+ "vite-plugin-singlefile": "^2.3.4",
85
+ "zod": "^4.6.7"
86
+ },
87
+ "devDependencies": {
88
+ "@anthropic-ai/claude-agent-sdk": "^0.3.328",
89
+ "@types/node": "^26.6.6",
90
+ "@types/react": "^19.3.0",
91
+ "@types/react-dom": "^19.3.0",
92
+ "react": "^19.3.1",
93
+ "react-dom": "^19.3.1",
94
+ "typescript": "^7.0.2",
95
+ "vitest": "^5.1.1"
96
+ },
97
+ "peerDependencies": {
98
+ "@anthropic-ai/claude-agent-sdk": ">=0.3.0",
99
+ "react": ">=18",
100
+ "react-dom": ">=18"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "@anthropic-ai/claude-agent-sdk": {
104
+ "optional": true
105
+ },
106
+ "react": {
107
+ "optional": true
108
+ },
109
+ "react-dom": {
110
+ "optional": true
111
+ }
112
+ },
113
+ "bugs": {
114
+ "url": "https://github.com/plugmcp-ai/plugmcp-framework/issues"
115
+ }
116
+ }