Skip to content

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Dec 7, 2025

Summary

  • Add new claude_agent module in mcp-codegen for generating Claude Agent SDK compatible TypeScript
  • Implement JSON Schema to Zod type mapping with format hints (.email(), .url(), etc.)
  • Add --generator claude-agent CLI flag for selecting output format
  • Create Handlebars templates for tool.ts, server.ts, and index.ts

Features

New Generator Module

  • claude_agent/generator.rs - Main generator for Claude Agent SDK format
  • claude_agent/types.rs - Context types for Handlebars templates
  • claude_agent/zod.rs - JSON Schema → Zod type conversion with modifiers

CLI Integration

# Generate Claude Agent SDK format
mcp-execution-cli generate --from-config github --generator claude-agent

Generated Structure

~/.claude/agent-sdk/{server-id}/
├── index.ts         # Entry point with exports
├── server.ts        # createSdkMcpServer() definition
└── tools/
    └── {tool}.ts    # Individual tools with Zod schemas

Example Generated Tool

import { tool } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";

export const createIssue = tool(
  "create_issue",
  "Creates a new issue",
  {
    repo: z.string().describe("Repository"),
    title: z.string().describe("Issue title"),
    body: z.string().optional()
  },
  async (args) => {
    return { content: [{ type: "text", text: JSON.stringify(args) }] };
  }
);

Test plan

  • All 475 existing tests pass
  • New unit tests for ClaudeAgentGenerator
  • New unit tests for Zod type conversion
  • Clippy passes without warnings
  • Documentation updated (README, ADR-012)

Related

Closes #29

- Add labeler workflow using actions/labeler@v5
- Configure rules for all 5 crates
- Add type labels: docs, ci, deps, tests, benchmarks, examples
- Add special labels: adr, security, breaking change, release, workspace
Add support for generating TypeScript tools compatible with Claude Agent SDK.
This new generator creates Zod schemas for type-safe tool definitions.

New features:
- New `claude_agent` module in mcp-codegen with generator, types, and zod conversion
- Handlebars templates for tool.ts, server.ts, and index.ts
- CLI `--generator claude-agent` flag for selecting output format
- JSON Schema to Zod type mapping with format hints (.email(), .url(), etc.)

Generated structure:
~/.claude/agent-sdk/{server-id}/
├── index.ts         # Entry point with exports
├── server.ts        # createSdkMcpServer() definition
└── tools/
    └── {tool}.ts    # Individual tools with Zod schemas

Usage:
  mcp-execution-cli generate --from-config github --generator claude-agent

Closes #29
@github-actions github-actions bot added crate: mcp-codegen Changes to mcp-codegen crate (TypeScript code generation) crate: mcp-cli Changes to mcp-cli crate (command-line interface) type: documentation Documentation changes (*.md, docs/, comments) type: ci CI/CD changes (.github/, workflows, automation) adr Architecture Decision Records (docs/adr/) breaking change Contains breaking API changes (requires major version bump) labels Dec 7, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2025

Codecov Report

❌ Patch coverage is 94.54191% with 56 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/mcp-codegen/src/claude_agent/zod.rs 84.83% 42 Missing ⚠️
crates/mcp-codegen/src/template_engine.rs 97.76% 9 Missing ⚠️
crates/mcp-codegen/src/claude_agent/generator.rs 98.06% 5 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #29      +/-   ##
==========================================
+ Coverage   93.79%   94.08%   +0.28%     
==========================================
  Files          14       17       +3     
  Lines        2723     3735    +1012     
==========================================
+ Hits         2554     3514     +960     
- Misses        169      221      +52     
Flag Coverage Δ
unittests 94.08% <94.54%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/mcp-codegen/src/claude_agent/types.rs 100.00% <100.00%> (ø)
crates/mcp-codegen/src/common/typescript.rs 97.04% <100.00%> (+0.09%) ⬆️
crates/mcp-codegen/src/claude_agent/generator.rs 98.06% <98.06%> (ø)
crates/mcp-codegen/src/template_engine.rs 96.24% <97.76%> (+11.01%) ⬆️
crates/mcp-codegen/src/claude_agent/zod.rs 84.83% <84.83%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a5296f...f2cb1bb. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bug-ops bug-ops removed the breaking change Contains breaking API changes (requires major version bump) label Dec 7, 2025
@github-actions github-actions bot added the breaking change Contains breaking API changes (requires major version bump) label Dec 7, 2025
Add 26 new tests to improve template engine test coverage:

- Claude Agent SDK template rendering tests
- Progressive loading template rendering tests
- Error handling tests (missing fields, invalid syntax)
- Edge case tests (unicode, special chars, empty arrays)
- Custom template tests (loops, conditionals, override)
- Strict mode and thread safety tests

Test coverage increased from 5 to 31 tests.
@bug-ops bug-ops force-pushed the feature/claude-agent-sdk-generator branch from d16aac5 to 6a7fe86 Compare December 7, 2025 13:13
@github-actions github-actions bot added the security Security-related changes (deny.toml, vulnerabilities) label Dec 7, 2025
Performance improvements:
- Replace Vec::insert(0) with direct assignment in integer handling
- Add with_capacity() hints for String and Vec allocations
- Inline format args for consistency

Code quality improvements:
- Consolidate IndexContext as type alias for ServerContext
- Add From<ZodPropertyInfo> for PropertyInfo conversion
- Make ZodPropertyInfo and extract_zod_properties pub(crate)
- Add #[must_use] attribute to generate() method
- Fix regex pattern escaping (escape forward slashes)

Test improvements:
- Add test for From trait implementation
- Add test for regex pattern escaping
- Fix numeric test value to avoid clippy::approx_constant
Update dependencies to latest versions:
- criterion: 0.7 → 0.8
- rmcp: 0.9 → 0.10
- uuid: 1.11 → 1.19

All 502 tests pass with updated dependencies.
@github-actions github-actions bot added type: dependencies Dependency updates (Cargo.toml, Cargo.lock) build Build configuration changes (build.rs, toolchain) workspace Workspace-wide changes affecting multiple crates release Release preparation (changelog, version bumps) labels Dec 7, 2025
Code quality improvements based on architect/security review:

- Replace .expect() with .ok_or_else() in common.rs:183
  (prevents panic from user input, returns proper error)
- Add # Errors sections to server.rs::run()
- Add # Errors sections to formatters.rs functions (4 functions)
- Remove #![allow(clippy::missing_errors_doc)] suppression
- Update build_server_config docs (remove Panics, expand Errors)

Security audit found only 1 production .expect() - now fixed.
All 502 tests pass.
Replace TODO comment with proper developer guidance:

- Add @remarks and @example JSDoc sections with implementation pattern
- Change silent stub to throw Error with clear message
- Remove misleading "MCP bridge" comment (bridge is user-implemented)

The stub now fails fast if called without implementation,
making it clear that developers need to provide their own logic.
@bug-ops bug-ops closed this Dec 7, 2025
@bug-ops bug-ops deleted the feature/claude-agent-sdk-generator branch December 7, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adr Architecture Decision Records (docs/adr/) breaking change Contains breaking API changes (requires major version bump) build Build configuration changes (build.rs, toolchain) crate: mcp-cli Changes to mcp-cli crate (command-line interface) crate: mcp-codegen Changes to mcp-codegen crate (TypeScript code generation) release Release preparation (changelog, version bumps) security Security-related changes (deny.toml, vulnerabilities) type: ci CI/CD changes (.github/, workflows, automation) type: dependencies Dependency updates (Cargo.toml, Cargo.lock) type: documentation Documentation changes (*.md, docs/, comments) workspace Workspace-wide changes affecting multiple crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants