import asyncio
from payments_py import Payments, PaymentOptions
# Initialize payments
payments = Payments.get_instance(
PaymentOptions(nvm_api_key="nvm:your-key", environment="sandbox")
)
# Define handlers
async def analyze_code(args, context=None):
"""Analyze code for issues."""
code = args.get("code", "")
language = args.get("language", "python")
# Your analysis logic here
issues = analyze(code, language)
return {
"content": [{
"type": "text",
"text": f"Found {len(issues)} issues in {language} code."
}]
}
async def get_docs(uri, variables, context=None):
"""Return documentation."""
topic = variables.get("topic", "general")
return {
"contents": [{
"uri": str(uri),
"mimeType": "text/markdown",
"text": f"# Documentation for {topic}\n\nContent here..."
}]
}
async def code_review_prompt(args, context=None):
"""Generate code review prompt."""
return {
"messages": [{
"role": "user",
"content": {
"type": "text",
"text": "Please review the following code for best practices..."
}
}]
}
# Register handlers
payments.mcp.register_tool(
"analyze_code",
{
"description": "Analyzes code for potential issues",
"inputSchema": {
"type": "object",
"properties": {
"code": {"type": "string"},
"language": {"type": "string", "default": "python"}
},
"required": ["code"]
}
},
analyze_code,
{"credits": 5} # 5 credits per analysis
)
payments.mcp.register_resource(
"docs://{topic}",
{
"name": "Documentation",
"description": "Technical documentation",
"mimeType": "text/markdown"
},
get_docs,
{"credits": 1}
)
payments.mcp.register_prompt(
"code_review",
{
"name": "Code Review",
"description": "Generates a code review prompt"
},
code_review_prompt,
{"credits": 2}
)
# Start server
async def main():
result = await payments.mcp.start({
"port": 5001,
"agentId": "agent-123",
"serverName": "code-assistant-mcp",
"version": "1.0.0"
})
print(f"MCP Server running at {result['info']['baseUrl']}")
print(f"Tools: {result['info']['tools']}")
print(f"Resources: {result['info']['resources']}")
print(f"Prompts: {result['info']['prompts']}")
# Keep running
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
await payments.mcp.stop()
asyncio.run(main())