@adhd/apigen-plugin-mcp 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.
@@ -0,0 +1,3 @@
1
+ import { PluginInput, PluginOutput } from '@adhd/apigen-core';
2
+
3
+ export declare function generate(input: PluginInput): PluginOutput;
@@ -0,0 +1,4 @@
1
+ import { OutputPlugin } from '@adhd/apigen-core';
2
+
3
+ export declare const mcpPlugin: OutputPlugin;
4
+ export default mcpPlugin;
package/lib/run.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { RunInput } from '@adhd/apigen-core';
2
+
3
+ export declare function run(input: RunInput): Promise<void>;
@@ -0,0 +1,47 @@
1
+ import { ApiStream } from '@adhd/apigen-runtime';
2
+
3
+ /** A single MCP content item (text carrier). */
4
+ export interface McpTextContent {
5
+ type: 'text';
6
+ text: string;
7
+ }
8
+ /** The MCP CallTool result envelope. */
9
+ export interface McpCallToolResult {
10
+ content: McpTextContent[];
11
+ isError?: boolean;
12
+ }
13
+ /**
14
+ * Drain `stream` and return the accumulated MCP result envelope.
15
+ *
16
+ * Chunks are collected in order; a terminal error after the first chunk is
17
+ * appended as an in-band error notification (`isError: true`).
18
+ *
19
+ * Because the MCP SDK's `CallToolRequestSchema` handler is a regular
20
+ * `async function` (returning a single value, not a generator), we cannot
21
+ * truly stream chunks over the wire — the SDK serialises the whole response
22
+ * once returned. The projection therefore **collects all chunks** and returns
23
+ * them as an ordered array of `content` items, which is the idiomatic MCP
24
+ * "progressive results" shape. Each chunk occupies one `content` slot in
25
+ * order.
26
+ *
27
+ * When the wire transport supports streaming (e.g. MCP over SSE with
28
+ * server-initiated notifications), a future revision may use
29
+ * `server.notification()` per chunk. The current shape is forward-compatible:
30
+ * the terminal item remains last.
31
+ *
32
+ * @param stream - the `ApiStream` returned by the Layer harness for a
33
+ * `streaming:true` operation.
34
+ * @returns a Promise resolving to the MCP `CallToolResult` envelope.
35
+ */
36
+ export declare function projectStreamMcp(stream: ApiStream<unknown>): Promise<McpCallToolResult>;
37
+ /**
38
+ * Drain `stream` collecting partial chunks AND the terminal error in-band.
39
+ *
40
+ * Unlike `projectStreamMcp`, this variant re-drives the stream manually to
41
+ * accumulate chunk values even when an error-after-first-chunk occurs, giving
42
+ * transport adapters the full `[chunk…, errorPayload]` content array.
43
+ *
44
+ * This is the **preferred** function for MCP transports that want to expose
45
+ * all partial data to the client.
46
+ */
47
+ export declare function projectStreamMcpFull(stream: ApiStream<unknown>): Promise<McpCallToolResult>;
@@ -0,0 +1,2 @@
1
+ /** Generates server.ts content for SSE or streaming-HTTP transport (uses node:http). */
2
+ export declare function generateHttpServer(transport: 'sse' | 'streaming-http', port: number): string;
@@ -0,0 +1,2 @@
1
+ /** Generates server.ts content for the stdio transport. */
2
+ export declare function generateStdioServer(): string;
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@adhd/apigen-plugin-mcp",
3
+ "version": "0.1.0",
4
+ "main": "./index.js",
5
+ "dependencies": {
6
+ "@adhd/apigen-core": "^0.1.0",
7
+ "@adhd/apigen-runtime": "^0.1.0",
8
+ "@modelcontextprotocol/sdk": "1.29.0"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.mjs",
14
+ "types": "./index.d.ts"
15
+ }