Coverage for src / mcp_server_langgraph / cli / __init__.py: 27%
86 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 00:43 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 00:43 +0000
1"""
2MCP Server with LangGraph CLI
4A command-line interface for scaffolding and managing MCP Server projects.
6Usage:
7 mcpserver init [--quickstart]
8 mcpserver create-agent <name> [--template <type>]
9 mcpserver add-tool <name>
10 mcpserver migrate --from <framework>
11"""
13import sys
15import click
17from .init import init_project
20@click.group()
21@click.version_option(version="2.8.0", prog_name="mcpserver")
22def cli() -> None:
23 """
24 MCP Server with LangGraph CLI
26 A production-ready MCP server with enterprise features.
28 Examples:
29 mcpserver init --quickstart
30 mcpserver create-agent my-agent --template research
31 mcpserver add-tool calculator
32 """
35@cli.command()
36@click.option(
37 "--quickstart",
38 is_flag=True,
39 help="Create a minimal quick-start project (no infrastructure)",
40)
41@click.option(
42 "--template",
43 type=click.Choice(["quickstart", "production", "enterprise"]),
44 default="production",
45 help="Project template to use",
46)
47@click.option(
48 "--name",
49 prompt="Project name",
50 help="Name of your MCP Server project",
51)
52def init(quickstart: bool, template: str, name: str) -> None:
53 """
54 Initialize a new MCP Server project.
56 Creates a new project with the specified template:
57 - quickstart: Minimal in-memory setup (2-minute start)
58 - production: Full Docker Compose stack (15-minute start)
59 - enterprise: Kubernetes with Keycloak + OpenFGA (1-2 hour setup)
61 Examples:
62 mcpserver init --quickstart --name my-agent
63 mcpserver init --template enterprise --name my-enterprise-agent
64 """
65 if quickstart:
66 template = "quickstart"
68 click.echo(f"Initializing MCP Server project: {name}")
69 click.echo(f"Template: {template}")
71 try:
72 init_project(name, template) # type: ignore[arg-type]
73 click.secho(f"✓ Project '{name}' created successfully!", fg="green")
75 if template == "quickstart":
76 click.echo("\nNext steps:")
77 click.echo(f" cd {name}")
78 click.echo(" uv run python app.py")
79 click.echo("\nYour agent will be running at http://localhost:8000")
80 elif template == "production":
81 click.echo("\nNext steps:")
82 click.echo(f" cd {name}")
83 click.echo(" docker compose up -d")
84 click.echo(" make setup")
85 click.echo("\nSee README.md for full setup instructions")
86 else:
87 click.echo("\nNext steps:")
88 click.echo(f" cd {name}")
89 click.echo(" See DEPLOYMENT.md for Kubernetes setup")
91 except Exception as e:
92 click.secho(f"✗ Error creating project: {e}", fg="red", err=True)
93 sys.exit(1)
96@cli.command()
97@click.argument("name")
98@click.option(
99 "--template",
100 type=click.Choice(["basic", "research", "customer-support", "code-review", "data-analyst"]),
101 default="basic",
102 help="Agent template to use",
103)
104@click.option(
105 "--tools",
106 multiple=True,
107 help="Tools to include (e.g., search, calculator)",
108)
109def create_agent(name: str, template: str, tools: tuple[str, ...]) -> None:
110 """
111 Create a new agent in the current project.
113 Generates an agent file with the specified template and tools.
115 Examples:
116 mcpserver create-agent my-agent
117 mcpserver create-agent researcher --template research --tools search
118 mcpserver create-agent support --template customer-support
119 """
120 click.echo(f"Creating agent: {name}")
121 click.echo(f"Template: {template}")
122 if tools:
123 click.echo(f"Tools: {', '.join(tools)}")
125 try:
126 from .create_agent import generate_agent
128 generate_agent(name, template, list(tools)) # type: ignore[arg-type]
129 click.secho(f"✓ Agent '{name}' created successfully!", fg="green")
130 click.echo(f"\nAgent file: src/agents/{name}_agent.py")
131 click.echo("\nNext steps:")
132 click.echo(f" 1. Edit src/agents/{name}_agent.py to customize behavior")
133 click.echo(" 2. Add tools in src/tools/ if needed")
134 click.echo(" 3. Test with: uv run python src/agents/{name}_agent.py")
136 except Exception as e:
137 click.secho(f"✗ Error creating agent: {e}", fg="red", err=True)
138 sys.exit(1)
141@cli.command()
142@click.argument("name")
143@click.option(
144 "--description",
145 prompt="Tool description",
146 help="What does this tool do?",
147)
148def add_tool(name: str, description: str) -> None:
149 """
150 Add a new tool to the current project.
152 Generates a tool file with boilerplate code.
154 Examples:
155 mcpserver add-tool calculator --description "Perform calculations"
156 mcpserver add-tool web-scraper --description "Scrape web pages"
157 """
158 click.echo(f"Creating tool: {name}")
159 click.echo(f"Description: {description}")
161 try:
162 from .add_tool import generate_tool
164 generate_tool(name, description)
165 click.secho(f"✓ Tool '{name}' created successfully!", fg="green")
166 click.echo(f"\nTool file: src/tools/{name}_tool.py")
167 click.echo("\nNext steps:")
168 click.echo(f" 1. Implement the tool logic in src/tools/{name}_tool.py")
169 click.echo(" 2. Add the tool to your agent")
170 click.echo(" 3. Test with: uv run pytest tests/tools/test_{name}_tool.py")
172 except Exception as e:
173 click.secho(f"✗ Error creating tool: {e}", fg="red", err=True)
174 sys.exit(1)
177@cli.command()
178@click.option(
179 "--from",
180 "from_framework",
181 type=click.Choice(["crewai", "langchain", "openai-agentkit", "autogpt"]),
182 required=True,
183 help="Framework to migrate from",
184)
185@click.option(
186 "--input",
187 "input_path",
188 type=click.Path(exists=True),
189 required=True,
190 help="Path to existing project",
191)
192def migrate(from_framework: str, input_path: str) -> None:
193 """
194 Migrate from another agent framework to MCP Server with LangGraph.
196 Converts existing agent code to MCP Server format.
198 Examples:
199 mcpserver migrate --from crewai --input ./my-crew
200 mcpserver migrate --from openai-agentkit --input ./my-agent
201 """
202 click.echo(f"Migrating from {from_framework}")
203 click.echo(f"Input: {input_path}")
205 click.secho("⚠ Migration tool coming in Q2 2025", fg="yellow")
206 click.echo("\nFor now, see our migration guides:")
207 click.echo(f" https://docs.mcp-server-langgraph.com/comparisons/vs-{from_framework}")
209 sys.exit(0)
212def main() -> None:
213 """Main entry point for the CLI."""
214 cli()
217if __name__ == "__main__":
218 main()