#!/usr/bin/env python3
"""
Basic usage example for POEditor MCP Server
This example demonstrates how to use the POEditor MCP server
to perform common translation management tasks.
"""
import asyncio
import json
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
"""Run basic POEditor MCP usage examples."""
print("🌟 POEditor MCP Server - Basic Usage Example")
print("=" * 50)
# Connect to the MCP server
server_params = StdioServerParameters(
command="python",
args=["-m", "mcp_poeditor"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize the session
await session.initialize()
print("\n📋 Available Tools:")
tools = await session.list_tools()
for tool in tools:
print(f" • {tool.name}: {tool.description}")
print("\n🔍 Listing Projects:")
try:
result = await session.call_tool("list_projects", {})
for content in result.content:
if hasattr(content, 'text'):
print(content.text)
except Exception as e:
print(f"Error: {e}")
# Example: Get project statistics
print("\n📊 Project Statistics Example:")
print("Note: Replace 'YOUR_PROJECT_ID' with an actual project ID")
# Uncomment and modify these lines to test with your actual project:
# try:
# result = await session.call_tool("get_project_stats", {
# "project_id": "YOUR_PROJECT_ID"
# })
# for content in result.content:
# if hasattr(content, 'text'):
# print(content.text)
# except Exception as e:
# print(f"Error: {e}")
print("\n✅ Example completed successfully!")
print("\nNext steps:")
print("1. Set up your POEditor API token in .env file")
print("2. Replace placeholder project IDs with real ones")
print("3. Explore more tools like add_language, create_project, etc.")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n👋 Example interrupted by user")
except Exception as e:
print(f"\n❌ Error running example: {e}")
print("\nTroubleshooting:")
print("1. Make sure the POEditor MCP server is properly installed")
print("2. Check your .env file configuration")
print("3. Verify your POEditor API token is valid")