"""
Generated MCP Wrapper: {{mcpName}}
This file was auto-generated by code-executor-mcp.
DO NOT EDIT MANUALLY - changes will be overwritten on next generation.
Generated: {{generatedAt}}
Schema Hash: {{schemaHash}}
Tool Count: {{toolCount}}
See: https://github.com/aberemia24/code-executor-MCP
"""
from typing import Any, Dict, Optional, List, TypedDict
import json
import os
import requests
class ExecutionResult(TypedDict):
"""Result from MCP tool execution"""
success: bool
output: str
error: Optional[str]
executionTimeMs: int
toolCallsMade: Optional[List[str]]
class {{pascalCase mcpName}}Client:
"""
MCP Server: {{mcpName}}
{{#if description}}
Description: {{description}}
{{/if}}
Available Tools: {{toolCount}}
"""
def __init__(
self,
proxy_url: Optional[str] = None,
auth_token: Optional[str] = None
):
"""
Initialize {{mcpName}} MCP client.
Args:
proxy_url: URL of code-executor-mcp proxy server
(defaults to CODE_EXECUTOR_PROXY_URL env var or http://localhost:3000)
auth_token: Bearer token for authentication
(defaults to CODE_EXECUTOR_AUTH_TOKEN env var, required)
Raises:
ValueError: If auth_token is not provided and CODE_EXECUTOR_AUTH_TOKEN is not set
"""
self.proxy_url = proxy_url or os.getenv('CODE_EXECUTOR_PROXY_URL', 'http://localhost:3000')
self.auth_token = auth_token or os.getenv('CODE_EXECUTOR_AUTH_TOKEN')
if not self.auth_token:
raise ValueError('auth_token must be provided or CODE_EXECUTOR_AUTH_TOKEN environment variable must be set')
def _call_mcp(self, tool_name: str, params: Dict[str, Any], timeout_ms: int = 30000) -> ExecutionResult:
"""
Internal method to call MCP tool via code-executor proxy.
Args:
tool_name: MCP tool name
params: Tool parameters
timeout_ms: Execution timeout in milliseconds
Returns:
ExecutionResult with output and metadata
Raises:
requests.HTTPError: If MCP call fails
"""
code = f"""
const result = await callMCPTool('{tool_name}', {json.dumps(params)});
console.log(JSON.stringify(result));
"""
response = requests.post(
self.proxy_url,
json={
"toolName": "executeTypescript",
"params": {
"code": code,
"allowedTools": [tool_name],
"timeoutMs": timeout_ms
}
},
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {self.auth_token}"
}
)
response.raise_for_status()
return response.json()
{{#each tools}}
def {{snakeCase (camelCase this.name)}}(
self,
{{#if this.inputSchema.properties}}
{{#each this.inputSchema.properties}}
{{snakeCase @key}}: {{pythonType this.type}}{{#unless (lookup ../this.inputSchema.required @key)}} = None{{/unless}},
{{/each}}
{{/if}}
) -> ExecutionResult:
"""
{{this.description}}
Tool: {{this.name}}
{{#if this.inputSchema.properties}}
Args:
{{#each this.inputSchema.properties}}
{{snakeCase @key}}: {{#if this.description}}{{this.description}}{{else}}{{this.type}} parameter{{/if}}{{#if (lookup ../this.inputSchema.required @key)}} (required){{/if}}
{{/each}}
{{/if}}
Returns:
ExecutionResult with output and metadata
Example:
>>> client = {{pascalCase ../mcpName}}Client()
>>> result = client.{{snakeCase (camelCase this.name)}}(
{{#if this.inputSchema.properties}}
{{#each this.inputSchema.properties}}
... {{snakeCase @key}}={{#if (eq this.type "string")}}'example'{{else if (eq this.type "number")}}123{{else if (eq this.type "boolean")}}True{{else if (eq this.type "array")}}[]{{else}}{}{{/if}},
{{/each}}
{{/if}}
... )
>>> print(result['output'])
"""
params = {
{{#each this.inputSchema.properties}}
'{{@key}}': {{snakeCase @key}},
{{/each}}
}
# Remove None values for optional parameters
params = {k: v for k, v in params.items() if v is not None}
return self._call_mcp('{{this.name}}', params)
{{/each}}
# Convenience functions for direct usage
{{#each tools}}
def {{snakeCase (camelCase this.name)}}(
{{#if this.inputSchema.properties}}
{{#each this.inputSchema.properties}}
{{snakeCase @key}}: {{pythonType this.type}}{{#unless (lookup ../this.inputSchema.required @key)}} = None{{/unless}},
{{/each}}
{{/if}}
proxy_url: Optional[str] = None,
auth_token: Optional[str] = None
) -> ExecutionResult:
"""
Convenience function for {{this.name}}.
{{this.description}}
{{#if this.inputSchema.properties}}
Args:
{{#each this.inputSchema.properties}}
{{snakeCase @key}}: {{#if this.description}}{{this.description}}{{else}}{{this.type}} parameter{{/if}}{{#if (lookup ../this.inputSchema.required @key)}} (required){{/if}}
{{/each}}
{{/if}}
proxy_url: URL of code-executor-mcp proxy server
(defaults to CODE_EXECUTOR_PROXY_URL env var or http://localhost:3000)
auth_token: Bearer token for authentication
(defaults to CODE_EXECUTOR_AUTH_TOKEN env var, required)
Returns:
ExecutionResult with output and metadata
Raises:
ValueError: If auth_token is not provided and CODE_EXECUTOR_AUTH_TOKEN is not set
"""
client = {{pascalCase ../mcpName}}Client(proxy_url, auth_token)
return client.{{snakeCase (camelCase this.name)}}(
{{#each this.inputSchema.properties}}
{{snakeCase @key}}={{snakeCase @key}},
{{/each}}
)
{{/each}}