# Directory Structure ``` ├── .gitignore ├── README.md └── wp-server-python ├── requirements.txt └── wp.py ``` # Files -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- ``` build/ # Node-generated files node_modules/ # Python-generated files __pycache__/ *.py[oc] dist/ wheels/ *.egg-info # Virtual environments .venv ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- ```markdown # Very much a work in progress that has not progressed You should go to https://github.com/Automattic/wordpress-mcp for a fully functional WordPress MCP implementation. To try it you currently need a WordPress instance locally on `http://localhost:8888/`. It is currently a python app, I used `uv` locally,so you will need to: `uv venv` `source .venv/bin/activate` `uv pip install -r requirements.txt` You can then run the server with `uv run wp.py` to see if you get any errors, but you don't need to run from terminal as Claude will start its own instance. You also need to add the following to your `claude_desktop_config.json`: ``` { "mcpServers": { "wordpress": { "command": "uv", "args": [ "--directory", "/FULL/PATH/TO/wp-server-python", "run", "wp.py" ] } } } ``` ``` -------------------------------------------------------------------------------- /wp-server-python/requirements.txt: -------------------------------------------------------------------------------- ``` httpx>=0.25.0 fastmcp>=0.1.0 ``` -------------------------------------------------------------------------------- /wp-server-python/wp.py: -------------------------------------------------------------------------------- ```python from typing import Any import httpx from mcp.server.fastmcp import FastMCP # Initialize FastMCP server mcp = FastMCP("wordpress") # Constants WP_API_BASE = "http://localhost:8888/wp-json/wp/v2" USER_AGENT = "wp-mcp/1.0" async def make_wp_request(url: str) -> dict[str, Any] | None: """Make a request to the WordPress API with proper error handling.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception as e: return {"error": str(e)} def format_post(post: dict) -> str: """Format a WordPress post into a readable string.""" return f""" Title: {post.get('title', {}).get('rendered', 'Untitled')} Status: {post.get('status', 'unknown')} Date: {post.get('date', 'unknown')} Link: {post.get('link', 'unknown')} Excerpt: {post.get('excerpt', {}).get('rendered', 'No excerpt available').strip()} """ def format_page(page: dict) -> str: """Format a WordPress page into a readable string.""" return f""" Title: {page.get('title', {}).get('rendered', 'Untitled')} Status: {page.get('status', 'unknown')} Date: {page.get('date', 'unknown')} Link: {page.get('link', 'unknown')} Parent: {page.get('parent', 0)} Menu Order: {page.get('menu_order', 0)} """ @mcp.tool() async def wp_list_posts() -> str: """Get a list of public posts from WordPress. Returns a formatted string containing post information. """ url = f"{WP_API_BASE}/posts" data = await make_wp_request(url) if not data: return "Unable to fetch posts." if isinstance(data, dict) and "error" in data: return f"Error fetching posts: {data['error']}" if not data: return "No posts found." posts = [format_post(post) for post in data] return "\n---\n".join(posts) @mcp.tool() async def wp_list_pages() -> str: """Get a list of pages from WordPress. Returns a formatted string containing page information. """ url = f"{WP_API_BASE}/pages" data = await make_wp_request(url) if not data: return "Unable to fetch pages." if isinstance(data, dict) and "error" in data: return f"Error fetching pages: {data['error']}" if not data: return "No pages found." pages = [format_page(page) for page in data] return "\n---\n".join(pages) if __name__ == "__main__": # Initialize and run the server mcp.run(transport='stdio') ```