﻿# RimAPI MCP Server

Python MCP server that exposes RimWorld REST API (RIMAPI) endpoints as MCP tools and resources.


## Requirements
- Python 3.10+
- `mcp>=1.2.0`

## Game prerequisites
For this MCP server to work correctly, the RIMAPI mod must be installed and enabled in RimWorld, and a game save must be loaded (a running game session).

## Install (optional)
If you only need to run the script, install `mcp`:
```powershell
python -m venv .venv
.\.venv\Scripts\python -m pip install mcp>=1.2.0
```

## Configuration (ENV)
- `RIMAPI_BASE_URL` (default `http://localhost:8765`)

## Run (stdio)
```powershell
$env:RIMAPI_BASE_URL = 'http://localhost:8765'
.\.venv\Scripts\python src\mcp_server.py
```

Note: with `stdio` transport, the MCP client must start the server process. If you run it manually without a client, it may exit immediately when stdin closes.

## Client setup (stdio)
Generic example for a MCP client that spawns a stdio server:
```python
MCPServerStdio(
    name="rimapi-mcp",
    params={
        "command": r"c:\\Projects\\RimAPI_MCP_Server\\.venv\\Scripts\\python",
        "args": [r"c:\\Projects\\RimAPI_MCP_Server\\src\\mcp_server.py"],
        "cwd": r"c:\\Projects\\RimAPI_MCP_Server",
        "env": {
            "MCP_TRANSPORT": "stdio",
            "RIMAPI_BASE_URL": "http://localhost:8765",
        },
    },
)
```

If the client does not accept absolute paths, set `cwd` and use `args: ["src/mcp_server.py"]`.

## Acknowledgements
Thanks to the RIMAPI mod by IlyaChichkov for making this MCP server possible:
`https://github.com/IlyaChichkov/RIMAPI`
