The personal finance app for everyone (by everyone)
Ruby
docs: refresh Sure MCP and external AI setup (#2608)
Sure Admin (bot)5c1808608914
diff --git a/docs/hosting/ai.md b/docs/hosting/ai.mdindex 9b844bd535..9540900ef0 100644--- a/docs/hosting/ai.md+++ b/docs/hosting/ai.md@@ -362,7 +362,7 @@ This is useful when:1. User sends a message in the Sure chat UI2. Sure sends the conversation to your agent's API endpoint (OpenAI chat completions format)3. Your agent processes it using whatever LLM, tools, or context it needs-4. Your agent can call Sure's `/mcp` endpoint for financial data (accounts, transactions, balance sheet, holdings)+4. Your agent can call Sure's `/mcp` endpoint for financial data and actions (accounts, transactions, balance sheet, budgets, file search, statement import, goals)5. Your agent streams the response back to Sure via Server-Sent Events (SSE)The agent's API must be **OpenAI chat completions compatible**: accept `POST` with a `messages` array, return SSE with `delta.content` chunks.@@ -397,18 +397,25 @@ Sure exposes a [Model Context Protocol](https://modelcontextprotocol.io/) (MCP)**Authentication:** Bearer token via `Authorization` header-**Environment variables:**+Sure supports both:++- OAuth bearer tokens issued through its discovery and registration endpoints (`/.well-known/oauth-protected-resource`, `/.well-known/oauth-authorization-server`, `POST /register`)+- Static bearer tokens configured with `MCP_API_TOKEN` and `MCP_USER_EMAIL`++**Static-token environment variables:**```bashMCP_API_TOKEN=your-secret-token # Bearer token the agent sends to authenticate[email protected] # Email of the Sure user the agent acts as```The agent must send requests to `https://your-sure-instance/mcp` with:-```-Authorization: Bearer <MCP_API_TOKEN>+```http+Authorization: Bearer <access-token>Content-Type: application/json```+For OAuth clients, `<access-token>` is the issued Doorkeeper bearer token. For static-token clients, it is the configured `MCP_API_TOKEN`.+**Supported methods:**| Method | Description |@@ -417,7 +424,7 @@ Content-Type: application/json| `tools/list` | Lists available tools with names, descriptions, and input schemas || `tools/call` | Calls a specific tool by name with arguments |-**Available tools** (exposed via `tools/list`):+**Base tools** (exposed via `tools/list`; treat the live response as the source of truth):| Tool | Description ||------|-------------|@@ -426,8 +433,20 @@ Content-Type: application/json| `get_holdings` | Investment holdings data || `get_balance_sheet` | Current financial position || `get_income_statement` | Income and expenses |+| `get_budget` | Budget status and category breakdowns || `import_bank_statement` | Import bank statement data |-| `search_family_files` | Search uploaded documents |+| `search_family_files` | Search documents uploaded through the import flow |+| `create_goal` | Create a savings goal |+| `get_tags` | List family tags |+| `create_tag` | Create a family tag |+| `update_tag` | Update a family tag |+| `get_categories` | List family categories |+| `create_category` | Create a family category |+| `update_category` | Update a family category |+| `update_transaction` | Update an existing transaction |+| `update_budget` | Update a budget category allocation |++Preview users may also see Statement Vault tools in `tools/list`.**Example: list tools**```bash@@ -699,8 +718,10 @@ def self.function_classesFunction::GetHoldings,Function::GetBalanceSheet,Function::GetIncomeStatement,+ Function::GetBudget,Function::ImportBankStatement,- Function::SearchFamilyFiles+ Function::SearchFamilyFiles,+ Function::CreateGoal]end```@@ -1234,8 +1255,10 @@ The assistant uses OpenAI's function calling (tool use) to access user data:- `get_holdings` - Investment holdings data- `get_balance_sheet` - Current financial position- `get_income_statement` - Income and expenses+- `get_budget` - Budget status and category breakdowns- `import_bank_statement` - Import bank statement data- `search_family_files` - Search uploaded documents+- `create_goal` - Create a savings goalThese are defined in `app/models/assistant/function/`.diff --git a/docs/hosting/docker.md b/docs/hosting/docker.mdindex e6d7d4f44a..99c5fe8c39 100644--- a/docs/hosting/docker.md+++ b/docs/hosting/docker.md@@ -185,7 +185,7 @@ The first time you run the app, you will need to register a new account by hittiAfter creating your initial admin account, you can control how other people join your self-hosted instance from **Settings > Self-Hosting > Onboarding**.- **Open**: Anyone can create an account from the registration page.-- **Invite-only**: New account creation stays enabled, but signups require a valid invite code.+- **Invite-only**: New account creation stays enabled. Signups require a valid invite code unless you configure a default family for invite-only onboarding.- **Closed**: The registration page is disabled for new signups.If you do not want additional self-service registrations, switch the instance to **Closed** after the initial setup.diff --git a/docs/hosting/hetzner.md b/docs/hosting/hetzner.mdindex c75ab76e5e..7e6227a643 100644--- a/docs/hosting/hetzner.md+++ b/docs/hosting/hetzner.md@@ -181,7 +181,7 @@ Now you can:Once your initial admin account is ready, open **Settings > Self-Hosting > Onboarding** to choose how signups should work:- **Open**: Anyone can register.-- **Invite-only**: New signups require a valid invite code.+- **Invite-only**: New signups require a valid invite code unless you configure a default family for invite-only onboarding.- **Closed**: New signups from the registration page are blocked.For single-admin or tightly controlled deployments, set the onboarding mode to **Closed** after the initial setup.diff --git a/docs/hosting/mcp.md b/docs/hosting/mcp.mdindex 64ef5412fa..8632fc7348 100644--- a/docs/hosting/mcp.md+++ b/docs/hosting/mcp.md@@ -1,6 +1,6 @@# MCP Server for External AI Assistants-Sure includes a Model Context Protocol (MCP) server endpoint that allows external AI assistants like Claude Desktop, GPT agents, or custom AI clients to query your financial data.+Sure includes a Model Context Protocol (MCP) server endpoint that allows external AI assistants like Claude.ai, Claude Desktop, GPT agents, or custom AI clients to query and act on your financial data.## What is MCP?@@ -11,9 +11,25 @@ This is useful when:- You prefer to keep your LLM provider separate from Sure- You're building custom AI agents that need access to financial tools-## Prerequisites+## Authentication Modes-For legacy bearer-token authentication, set these two environment variables:+Sure supports two ways to authenticate MCP clients:++### 1. OAuth 2.0 / dynamic client registration (recommended)++This is the best option for Claude.ai and other MCP clients that support OAuth. Sure exposes:++- `/.well-known/oauth-protected-resource`+- `/.well-known/oauth-authorization-server`+- `POST /register` for dynamic client registration++These endpoints let compatible MCP clients register a public OAuth client, redirect you back to Sure for sign-in, and receive a bearer token with the `read_write` scope.++### 2. Static bearer token via environment variables++This is the simpler fallback for custom agents, scripts, and deployments where you want to pin the MCP server to a specific Sure user.++Set these environment variables:| Variable | Description | Example ||----------|-------------|---------|@@ -34,12 +50,12 @@ openssl rand -base64 32# Or use any secure password generator```-### Choosing the user+### Choosing the user for static-token authThe `MCP_USER_EMAIL` must match an existing Sure user's email address. The AI assistant will have access to all financial data for that user's family.> [!CAUTION]-> The AI assistant will have **read access to all financial data** for the specified user. Only set this for users you trust with your AI provider.+> The AI assistant can call the MCP tools available to the specified user. This includes reading financial data and write-capable tools such as statement import, goal/category/tag changes, transaction updates, and budget updates. Only set this for users you trust with your AI provider.## Configuration@@ -93,9 +109,14 @@ For self-hosted deployments or clients without OAuth support, requests may usethe legacy `MCP_API_TOKEN` as a Bearer token:```-Authorization: Bearer <MCP_API_TOKEN>+Authorization: Bearer <token>```+That token can come from either:++- an OAuth authorization flow handled by the MCP client, or+- the static `MCP_API_TOKEN` environment variable described above.+### Supported MethodsSure implements the following JSON-RPC 2.0 methods:@@ -108,7 +129,9 @@ Sure implements the following JSON-RPC 2.0 methods:### Available Tools-The MCP endpoint exposes these financial tools:+The MCP endpoint exposes the same tool registry used by Sure's built-in assistant. Clients should treat `tools/list` as the source of truth.++At the time of writing, `tools/list` includes:| Tool | Description ||------|-------------|@@ -117,10 +140,20 @@ The MCP endpoint exposes these financial tools:| `get_holdings` | Query investment holdings || `get_balance_sheet` | Current financial position (assets, liabilities, net worth) || `get_income_statement` | Income and expenses over a period |+| `get_budget` | Budget status and budget category breakdowns || `import_bank_statement` | Import bank statement data || `search_family_files` | Search documents uploaded through the import flow. Note this is the vector-store document index, not the Statement Vault — statements archived via `upload_account_statement` are not searchable through it |--These are the same tools used by Sure's builtin AI assistant.+| `create_goal` | Create a savings goal linked to depository accounts |+| `get_tags` | List family tags |+| `create_tag` | Create a family tag |+| `update_tag` | Update a family tag |+| `get_categories` | List family categories |+| `create_category` | Create a family category |+| `update_category` | Update a family category |+| `update_transaction` | Update an existing transaction |+| `update_budget` | Update a budget category allocation |++These are the same tools used by Sure's built-in AI assistant.### Preview Tools@@ -195,6 +228,22 @@ curl -X POST https://your-sure-instance/mcp \Response includes tool names, descriptions, and JSON schemas for parameters.+### OAuth discovery++MCP clients that support OAuth can discover Sure's metadata automatically:++```bash+curl https://your-sure-instance/.well-known/oauth-protected-resource+curl https://your-sure-instance/.well-known/oauth-authorization-server+```++The authorization-server metadata includes:++- `authorization_endpoint`: `https://your-sure-instance/oauth/authorize`+- `token_endpoint`: `https://your-sure-instance/oauth/token`+- `registration_endpoint`: `https://your-sure-instance/register`+- `scopes_supported`: `["read_write"]`+### Call a ToolExecute a tool to get transactions:@@ -242,7 +291,7 @@ The MCP controller creates a **transient session** for each request. This prevenEach MCP request:1. Authenticates the token-2. Loads the user specified in `MCP_USER_EMAIL`+2. Loads the authorized Sure user3. Creates a temporary session scoped to that user4. Executes the tool call5. Discards the session@@ -310,14 +359,25 @@ The Pipelock proxy (port 8889) scans all MCP traffic before forwarding to Sure's## Connecting AI Assistants+### Claude.ai++Sure's Settings UI is already geared toward Claude.ai OAuth integrations:++1. Open **Settings -> Integrations** in Claude.ai+2. Click **Add integration**+3. Paste your Sure MCP URL+4. Claude redirects you to Sure to sign in and authorize access++If you are using Pipelock, use the reverse-proxy URL on port `8889`. Otherwise use the app URL ending in `/mcp`.+### Claude Desktop-Configure Claude Desktop to use Sure's MCP server:+If your Claude Desktop build expects a raw MCP endpoint instead of an OAuth integration flow, point it at:++- `http://your-server:8889` when using Pipelock, or+- `http://your-server:3000/mcp` for direct access-1. Open Claude Desktop settings-2. Add a new MCP server-3. Set the endpoint to `http://your-server:8889` (if using Pipelock) or `http://your-server:3000/mcp`-4. Add the authorization header: `Authorization: Bearer your-secret-token`+Use either the client's OAuth support or a bearer token, depending on what that build supports.### Custom Agents@@ -330,23 +390,21 @@ Any AI agent that supports JSON-RPC 2.0 can connect to the MCP endpoint. The age## Troubleshooting-### "MCP endpoint not configured" error--**Symptom:** Requests return HTTP 503 with "MCP endpoint not configured"--**Fix:** Ensure both `MCP_API_TOKEN` and `MCP_USER_EMAIL` are set as environment variables and restart Sure.-### "unauthorized" error**Symptom:** Requests return HTTP 401 with "unauthorized"-**Fix:** Verify the `Authorization` header contains the correct token: `Bearer <MCP_API_TOKEN>`+**Fix:** Verify one of these is true:++- The OAuth flow completed successfully and the client is sending the issued bearer token+- The static token matches `MCP_API_TOKEN`+- If you are using the static-token flow, `MCP_USER_EMAIL` matches an existing Sure user-### "MCP user not configured" error+### Static token works, but the user still gets rejected-**Symptom:** Requests return HTTP 503 with "MCP user not configured"+**Symptom:** Requests return HTTP 401 even though the bearer token matches `MCP_API_TOKEN`-**Fix:** The `MCP_USER_EMAIL` does not match an existing user. Check that:+**Fix:** The `MCP_USER_EMAIL` probably does not match an existing user. Check that:- The email is correct- The user exists in the database- There are no typos or extra spaces