Skip to content

Commit 1b5bae5

Browse files
committed
refactor(mcpc): simplify API with AgentOptions and add defaults
- Add AgentOptions interface for advanced options (maxSteps, maxTokens, tracingEnabled, samplingConfig, providerOptions, acpSettings, refs) - Simplify AgentDef from 13 fields to 6 fields (name, description, mcpServers, mode, plugins, options) - Add global plugins support that apply to all agents - Add default values: version='1.0.0', capabilities={ tools: { listChanged: true } } - Add 'agent' singular field for simpler single-agent configs - Add mcpc_api_test.ts with 10 tests covering new API - Update examples to use new structure
1 parent adfbe36 commit 1b5bae5

37 files changed

+1050
-315
lines changed

packages/cli/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OpenAPIHono } from "@hono/zod-openapi";
22
import { registerAgent } from "./controllers/register.ts";
3-
import { mcpc } from "@mcpc/core";
3+
import { mcpcLegacy } from "@mcpc/core";
44
import { createLargeResultPlugin } from "@mcpc/core/plugins/large-result";
55
import type { ComposableMCPServer, ComposeDefinition } from "@mcpc/core";
66
import type { MCPCConfig } from "./config/loader.ts";
@@ -25,7 +25,7 @@ export const createServer = async (
2525
] as ComposeDefinition[],
2626
};
2727

28-
return await mcpc(
28+
return await mcpcLegacy(
2929
[
3030
{
3131
name: serverConfig.name || "mcpc-server",

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

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@
1111
*/
1212

1313
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
14-
import { type ComposeDefinition, mcpc } from "../mod.ts";
14+
import { mcpc } from "../mod.ts";
1515

16-
export const toolDefinitions: ComposeDefinition[] = [
17-
{
18-
name: "file-organizer",
19-
description:
20-
`I am a smart file organizer that helps users manage their files efficiently.
16+
export const server = await mcpc({
17+
name: "basic-file-manager",
18+
version: "1.0.0",
19+
capabilities: {
20+
tools: { listChanged: true },
21+
},
22+
23+
agents: [
24+
{
25+
name: "file-organizer",
26+
description:
27+
`I am a smart file organizer that helps users manage their files efficiently.
2128
2229
Available tools:
2330
<tool name="@wonderwhy-er/desktop-commander.list_directory"/>
2431
<tool name="@wonderwhy-er/desktop-commander.create_directory"/>
2532
<tool name="@wonderwhy-er/desktop-commander.move_file"/>
2633
<tool name="@wonderwhy-er/desktop-commander.read_file"/>
27-
<tool name="@wonderwhy-er/desktop-commander.write_file">
34+
<tool name="@wonderwhy-er/desktop-commander.write_file"/>
2835
2936
I can:
3037
1. List directory contents to understand the current file structure
@@ -36,34 +43,15 @@ I can:
3643
3744
I always ask for confirmation before making destructive changes and provide clear explanations of what I'm doing.`,
3845

39-
deps: {
4046
mcpServers: {
4147
"@wonderwhy-er/desktop-commander": {
4248
command: "npx",
4349
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
44-
transportType: "stdio" as const,
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,
6150
},
6251
},
6352
},
6453
],
65-
toolDefinitions,
66-
);
54+
});
6755

6856
const transport = new StdioServerTransport();
6957
await server.connect(transport);

packages/core/examples/02-agentic-data-analyst.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,15 @@
1414
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1515
import { mcpc } from "../mod.ts";
1616

17-
export const server = await mcpc(
18-
[
19-
{
20-
name: "agentic-data-analyst",
21-
version: "1.0.0",
22-
},
23-
{ capabilities: { tools: { listChanged: true } } },
24-
],
25-
[
17+
export const server = await mcpc({
18+
name: "agentic-data-analyst",
19+
version: "1.0.0",
20+
capabilities: { tools: { listChanged: true } },
21+
22+
agents: [
2623
{
2724
name: "data-analyst",
28-
29-
// Agentic mode for complete autonomy
30-
options: {
31-
mode: "agentic",
32-
},
25+
mode: "agentic",
3326

3427
description:
3528
`I am an autonomous data analyst that can perform comprehensive data analysis with complete freedom to orchestrate my actions.
@@ -60,22 +53,18 @@ I decide the order of operations dynamically based on:
6053
6154
My autonomous approach ensures thorough analysis tailored to each unique dataset.`,
6255

63-
deps: {
64-
mcpServers: {
65-
"code-runner": {
66-
command: "deno",
67-
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
68-
transportType: "stdio",
69-
},
70-
"@wonderwhy-er/desktop-commander": {
71-
command: "npx",
72-
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
73-
transportType: "stdio",
74-
},
56+
mcpServers: {
57+
"code-runner": {
58+
command: "deno",
59+
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
60+
},
61+
"@wonderwhy-er/desktop-commander": {
62+
command: "npx",
63+
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
7564
},
7665
},
7766
},
7867
],
79-
);
68+
});
8069

8170
await server.connect(new StdioServerTransport());

packages/core/examples/06-multi-mcp-web-analyzer.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@
1515
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1616
import { mcpc } from "../mod.ts";
1717

18-
export const server = await mcpc(
19-
[
20-
{
21-
name: "multi-mcp-web-analyzer",
22-
version: "1.0.0",
23-
},
24-
{ capabilities: { tools: { listChanged: true } } },
25-
],
26-
[
18+
export const server = await mcpc({
19+
name: "multi-mcp-web-analyzer",
20+
version: "1.0.0",
21+
capabilities: { tools: { listChanged: true } },
22+
23+
agents: [
2724
{
2825
name: "web-analyzer",
29-
30-
options: {
31-
mode: "agentic",
32-
},
26+
mode: "agentic",
3327

3428
description:
3529
`I am a comprehensive web analyzer that combines multiple MCP servers to perform sophisticated web content analysis and reporting.
@@ -83,27 +77,22 @@ I intelligently coordinate between browser automation, data processing, and file
8377
- PDF reports for sharing and presentation
8478
- Screenshots and visual documentation`,
8579

86-
deps: {
87-
mcpServers: {
88-
"@microsoft/playwright-mcp": {
89-
command: "npx",
90-
args: ["@playwright/mcp@latest", "--image-responses=emit"],
91-
transportType: "stdio",
92-
},
93-
"code-runner": {
94-
command: "deno",
95-
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
96-
transportType: "stdio",
97-
},
98-
"@wonderwhy-er/desktop-commander": {
99-
command: "npx",
100-
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
101-
transportType: "stdio",
102-
},
80+
mcpServers: {
81+
"@microsoft/playwright-mcp": {
82+
command: "npx",
83+
args: ["@playwright/mcp@latest", "--image-responses=emit"],
84+
},
85+
"code-runner": {
86+
command: "deno",
87+
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
88+
},
89+
"@wonderwhy-er/desktop-commander": {
90+
command: "npx",
91+
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
10392
},
10493
},
10594
},
10695
],
107-
);
96+
});
10897

10998
await server.connect(new StdioServerTransport());

packages/core/examples/07-runtime-transformations.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,17 @@ const _errorEnrichmentPlugin: ToolPlugin = {
119119

120120
// Example usage
121121
async function main() {
122-
const server = await mcpc(
123-
[{ name: "example-server", version: "1.0.0" }, {}],
124-
[],
125-
async (server) => {
126-
// Add runtime transformation plugins
127-
await server.addPlugin(inputSanitizationPlugin);
128-
await server.addPlugin(outputFormattingPlugin);
129-
await server.addPlugin(loggingPlugin);
122+
const server = await mcpc({
123+
name: "example-server",
124+
version: "1.0.0",
130125

126+
plugins: [
127+
inputSanitizationPlugin,
128+
outputFormattingPlugin,
129+
loggingPlugin,
130+
],
131+
132+
setup: (server) => {
131133
// Register a sample tool
132134
server.tool(
133135
"greet",
@@ -151,7 +153,7 @@ async function main() {
151153
},
152154
);
153155
},
154-
);
156+
});
155157

156158
// Test the tool - input will be sanitized, output will be formatted and logged
157159
const result = await server.callTool("greet", {

packages/core/examples/09-unified-prompt-management.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,31 @@ const agentDescription = fileOperationsDescription
9898
.replace("{hiddenTools}", hiddenTools)
9999
.replace("{wildcardTools}", wildcardTools);
100100

101-
export const server = await mcpc(
102-
[
103-
{
104-
name: "unified-prompt-manager",
105-
version: "1.0.0",
106-
},
107-
{ capabilities: { tools: { listChanged: true } } },
108-
],
109-
[
101+
export const server = await mcpc({
102+
name: "unified-prompt-manager",
103+
version: "1.0.0",
104+
capabilities: { tools: { listChanged: true } },
105+
106+
agents: [
110107
{
111108
name: "prompt-managed-agent",
112-
113-
// Use centralized description template
114109
description: agentDescription,
115110

116-
deps: {
117-
mcpServers: {
118-
"@wonderwhy-er/desktop-commander": {
119-
command: "npx",
120-
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
121-
},
122-
"code-runner": {
123-
command: "deno",
124-
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
125-
},
111+
mcpServers: {
112+
"@wonderwhy-er/desktop-commander": {
113+
command: "npx",
114+
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
115+
},
116+
"code-runner": {
117+
command: "deno",
118+
args: ["run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"],
126119
},
127120
},
128121
},
129122
],
123+
130124
// Demonstrate internal tool registration with centralized prompts
131-
(server) => {
125+
setup: (server) => {
132126
server.tool(
133127
"audit-logger",
134128
"Internal comprehensive audit logging with standardized format",
@@ -228,6 +222,6 @@ export const server = await mcpc(
228222
"📝 All prompts are now centrally managed and dynamically generated",
229223
);
230224
},
231-
);
225+
});
232226

233227
await server.connect(new StdioServerTransport());

packages/core/examples/11-large-result-plugin-agentic.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
*/
77

88
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9-
import { mcpc } from "../src/set-up-mcp-compose.ts";
10-
// import { createLargeResultPlugin } from "../plugins.ts";
9+
import { mcpc } from "../mod.ts";
1110
import { jsonSchema } from "../mod.ts";
1211

13-
const server = await mcpc(
14-
[{ name: "large-demo", version: "1.0.0" }, { capabilities: { tools: {} } }],
15-
[
12+
const server = await mcpc({
13+
name: "large-demo",
14+
version: "1.0.0",
15+
capabilities: { tools: {} },
16+
17+
agents: [
1618
{
1719
name: "large-output-handler",
1820
description:
1921
"Agent that demonstrates automatic large output handling and file storage",
2022
plugins: [
2123
"./plugins/large-result.ts?maxSize=8000&previewSize=4000",
22-
// create a large result plugin instance
23-
// createLargeResultPlugin(),
2424
],
2525
},
2626
],
27-
(server) => {
27+
28+
setup: (server) => {
2829
// Tool that makes big output
2930
server.tool(
3031
"make-big-text",
@@ -46,7 +47,7 @@ const server = await mcpc(
4647
{ internal: true },
4748
);
4849
},
49-
);
50+
});
5051

5152
const transport = new StdioServerTransport();
5253
await server.connect(transport);

0 commit comments

Comments
 (0)