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
24 changes: 23 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/cli/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mcpc/cli",
"version": "0.1.11",
"version": "0.1.12-beta.1",
"repository": {
"type": "git",
"url": "git+https://github.com/mcpc-tech/mcpc.git"
Expand All @@ -12,7 +12,7 @@
"./app": "./src/app.ts"
},
"imports": {
"@mcpc/core": "jsr:@mcpc/core@^0.3.1",
"@mcpc/core": "jsr:@mcpc/core@^0.3.2-beta.1",
"@mcpc/utils": "jsr:@mcpc/utils@^0.2.2",
"@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk@^1.8.0",
"@mcpc-tech/ripgrep-napi": "npm:@mcpc-tech/ripgrep-napi@^0.0.4",
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.3.1",
"version": "0.3.2-beta.1",
"repository": {
"type": "git",
"url": "git+https://github.com/mcpc-tech/mcpc.git"
Expand Down
83 changes: 83 additions & 0 deletions packages/core/examples/14-code-execution-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Example: Code Execution Mode (KISS Pattern)
*
* Demonstrates the simplified code execution pattern with clear parameter names.
* This example shows how to:
* 1. Use definitionsOf to get tool schemas
* 2. Execute JavaScript code with hasDefinitions declaring known tools
*
* Based on: https://www.anthropic.com/engineering/code-execution-with-mcp
*
* Simple workflow:
* 1. First call: { definitionsOf: ['read_file', 'move_file'] } - get schemas
* 2. Second call: {
* code: 'const result = await callMCPTool("read_file", {...})',
* hasDefinitions: ['read_file']
* } - execute code
*
* Key benefits:
* - Clear parameter names: definitionsOf, hasDefinitions, code
* - Schema enforces: code requires hasDefinitions (non-empty)
* - Both code and definitionsOf can be used together
* - Simple, intuitive workflow
*/

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

export const toolDefinitions: ComposeDefinition[] = [
{
name: "file-organizer",
description:
`I am a smart file organizer that helps users manage their files efficiently.

Available tools:
<tool name="@wonderwhy-er/desktop-commander.list_directory"/>
<tool name="@wonderwhy-er/desktop-commander.create_directory"/>
<tool name="@wonderwhy-er/desktop-commander.move_file"/>
<tool name="@wonderwhy-er/desktop-commander.read_file"/>
<tool name="@wonderwhy-er/desktop-commander.write_file">

I can:
1. List directory contents to understand the current file structure
2. Create new directories for organization
3. Move files to appropriate folders based on type, date, or content
4. Delete unnecessary files after confirmation
5. Read file contents to understand what they contain
6. Create new files or modify existing ones

I always ask for confirmation before making destructive changes and provide clear explanations of what I'm doing.`,
options: {
mode: "code_execution",
},
deps: {
mcpServers: {
"@wonderwhy-er/desktop-commander": {
command: "npx",
args: ["-y", "@wonderwhy-er/desktop-commander@latest"],
transportType: "stdio" as const,
},
},
},
},
];

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

const transport = new StdioServerTransport();
await server.connect(transport);
10 changes: 5 additions & 5 deletions packages/core/src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import { sortPluginsByOrder, validatePlugins } from "./plugin-utils.ts";
// Import new manager modules
import { PluginManager } from "./utils/plugin-manager.ts";
import { ToolManager } from "./utils/tool-manager.ts";
import { buildDependencyGroups } from "./utils/compose-helpers.ts";
import {
buildDependencyGroups,
processToolsWithPlugins,
} from "./utils/compose-helpers.ts";
import { sanitizePropertyKey } from "./utils/common/provider.ts";

const ALL_TOOLS_PLACEHOLDER = "__ALL__";
Expand Down Expand Up @@ -344,10 +347,7 @@ export class ComposableMCPServer extends Server {
externalTools: Record<string, ComposedTool>,
mode: ExecutionMode,
): Promise<void> {
const { processToolsWithPlugins: processTools } = await import(
"./utils/compose-helpers.ts"
);
await processTools(this, externalTools, mode);
await processToolsWithPlugins(this, externalTools, mode);
}

/**
Expand Down
21 changes: 2 additions & 19 deletions packages/core/src/executors/agentic/agentic-executor.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { Ajv } from "ajv";
import { AggregateAjvError } from "@segment/ajv-human-errors";
import addFormats from "ajv-formats";
import type { ComposableMCPServer } from "../../compose.ts";
import { CompiledPrompts } from "../../prompts/index.ts";
import { createLogger, type MCPLogger } from "../../utils/logger.ts";
import { validateSchema } from "../../utils/schema-validator.ts";
import type { Span } from "@opentelemetry/api";
import { endSpan, initializeTracing, startSpan } from "../../utils/tracing.ts";
import process from "node:process";

const ajv = new Ajv({
allErrors: true,
verbose: true,
});
// @ts-ignore -
addFormats(ajv);

export class AgenticExecutor {
private logger: MCPLogger;
private tracingEnabled: boolean = false;
Expand Down Expand Up @@ -313,14 +304,6 @@ export class AgenticExecutor {
if (args.decision === "complete") {
return { valid: true };
}
const validate = ajv.compile(schema);
if (!validate(args)) {
const errors = new AggregateAjvError(validate.errors!);
return {
valid: false,
error: errors.message,
};
}
return { valid: true };
return validateSchema(args, schema);
}
}
Loading