Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ You can use it to:

[Achieving Agent Interoperability](./learn-more/achieving-agent-interoperability.md)

[Speed Up MCPC with In-Memory Transport](./learn-more/speed-up-with-in-memory-transport.md)

[Plugin System](./plugins.md)

[Logging and Tracing](./logging-and-tracing.md)
Expand Down
14 changes: 11 additions & 3 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ That's it. The agent can now call these tools.

All MCP transports work:

- **stdio**
- **streamable-http**
- **sse**
- **stdio**: Spawns external processes
- **streamable-http**: HTTP-based communication
- **sse**: Server-Sent Events
- **memory**: In-memory transport for same-process communication

> **Performance Tip**: If MCPC feels slow, try using `memory` transport.
> Connecting multiple MCP servers has overhead - memory transport eliminates it.

> **Learn More**: See
> [Speed Up MCPC with In-Memory Transport](./learn-more/speed-up-with-in-memory-transport.md)
> for detailed examples and use cases.
89 changes: 89 additions & 0 deletions docs/learn-more/speed-up-with-in-memory-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Speed Up MCPC with In-Memory Transport

Connect MCP servers in the same process. No external processes, no network
overhead.

## Why Use It

**Zero overhead**: Same-process communication is instant\
**Simple testing**: No external dependencies to mock\
**Easy embedding**: Integrate MCP directly into your app

## Usage

**Step 1**: Create an MCP server

```typescript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

const myServer = new McpServer({ name: "my-server", version: "1.0.0" });

myServer.tool(
"greet",
"Greet a user",
{ name: "string" },
({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}),
);
```

**Step 2**: Pass server instance to MCPC

```typescript
import { mcpc } from "@mcpc/core";

const server = await mcpc(
[{ name: "my-agent", version: "1.0.0" }, { capabilities: { tools: {} } }],
[{
name: "greeter",
description: 'Available tools:\n<tool name="my-server.greet"/>',
deps: {
mcpServers: {
"my-server": {
transportType: "memory",
server: myServer, // Pass the server instance
},
},
},
}],
);
```

## The Advantage

**Other transports** spawn processes or make network calls:

```typescript
deps: {
mcpServers: {
"desktop-commander": {
command: "npx", // Spawns external process
args: ["-y", "@wonderwhy-er/desktop-commander"],
transportType: "stdio"
}
}
}
```

**Memory transport** runs in the same process:

```typescript
deps: {
mcpServers: {
"my-server": {
transportType: "memory",
server: myServerInstance, // Instant, no overhead
},
},
}
```

## Try the Example

```bash
deno run --allow-all packages/core/examples/13-in-memory-transport.ts
```

See the [example code](../../packages/core/examples/13-in-memory-transport.ts)
for a complete working implementation.
7 changes: 6 additions & 1 deletion docs/quickstart/create-your-first-agentic-mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See the magic in action 👇
The MCPC framework becomes truly powerful when you reuse and compose existing
MCP Servers, much like your favorite AI-integrated clients (e.g., Cursor or
VSCode). We offer full support for the MCP transport protocol, including
`stdio`, `sse`, and `streamable-http`.
`stdio`, `sse`, `streamable-http`, and `memory` (in-memory).

```typescript
import { type ComposeDefinition, mcpc } from "@mcpc/core";
Expand Down Expand Up @@ -71,6 +71,11 @@ const deps: ComposeDefinition["deps"] = {
};
```

> **💡 Tip**: For testing or embedding MCP servers in the same process, you can
> use `memory` transport. See
> [FAQ Q5](../faq.md#q5-what-transport-types-does-mcpc-support) for in-memory
> transport examples.

# Then write the documentation for your agent

A documentation for your agent helps LLM understand the purpose of the agent,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mcpc/cli",
"version": "0.1.9",
"version": "0.1.10",
"repository": {
"type": "git",
"url": "git+https://github.com/mcpc-tech/mcpc.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mcpc/core",
"version": "0.2.8",
"version": "0.2.9",
"repository": {
"type": "git",
"url": "git+https://github.com/mcpc-tech/mcpc.git"
Expand Down
95 changes: 95 additions & 0 deletions packages/core/examples/13-in-memory-transport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* MCPC Example 13: In-Memory Transport
*
* Demonstrates the in-memory transport feature:
* - Using InMemoryTransport for in-process communication
* - Useful for testing and embedding MCP servers
* - No external process spawning required
*
* This creates a file manager that communicates with an embedded MCP server
* via in-memory transport, perfect for testing and integration scenarios.
*/

import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { type ComposeDefinition, mcpc } from "../mod.ts";

// Create a simple in-memory MCP server for demonstration
function createTestMcpServer() {
const mcpServer = new McpServer({
name: "test-memory-server",
version: "1.0.0",
});

// Register a simple tool
mcpServer.tool(
"greet",
"Greet a user by name",
{ name: "string" },
({ name }) => ({
content: [{
type: "text" as const,
text:
`Hello, ${name}! This message comes from an in-memory MCP server.`,
}],
}),
);

return mcpServer;
}

// Initialize the in-memory server
const testServer = createTestMcpServer();

export const toolDefinitions: ComposeDefinition[] = [
{
name: "memory-agent",
description:
`I am an agent that uses in-memory transport to communicate with MCP servers.

Available tools:
<tool name="test-memory-server.greet"/>

I can greet users using the in-memory MCP server. This demonstrates how MCPC can work with
in-memory transports for testing and embedded scenarios where you don't want to spawn
external processes.`,

deps: {
mcpServers: {
"test-memory-server": {
transportType: "memory" as const,
server: testServer,
},
},
},
},
];

export const server = await mcpc(
[
{
name: "in-memory-example",
version: "1.0.0",
},
{
capabilities: {
tools: {
listChanged: true,
},
},
},
],
toolDefinitions,
);

// Only run if executed directly
if (import.meta.main) {
console.log("Starting In-Memory Transport Example Server...");
console.log("\nThis example demonstrates in-memory transport:");
console.log("- No external processes spawned");
console.log("- Useful for testing and embedding");
console.log("- Fast and efficient for in-process communication\n");

await server.connect(new StdioServerTransport());
console.log("Server running with in-memory transport support!");
}
7 changes: 7 additions & 0 deletions packages/core/src/service/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ export const StdioConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> =
transportType: z.literal("stdio").optional(),
});

export const InMemoryConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> =
BaseConfigSchema.extend({
transportType: z.literal("memory"),
server: z.any(), // Server instance from @modelcontextprotocol/sdk
});

export const ServerConfigSchema: z.ZodTypeAny = z.union([
StdioConfigSchema,
SseConfigSchema,
StreamableHTTPSchema,
InMemoryConfigSchema,
]);

export const McpSettingsSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = z
Expand Down
Loading
Loading