Skip to main content
Glama
parqet-broker

parqet-broker

by joednemesis
README.md
[Deutsch](README.de.md) | [English](README.md)
# Parqet MCP Broker

A lightweight Flask-based broker that acts as a **Model Context Protocol (MCP) intermediary** between the [Parqet](https://parqet.com) portfolio tracking platform and a locally running LLM in [LM Studio](https://lmstudio.ai). It handles OAuth 2.0 authentication with Parqet, maintains a persistent MCP session, and exposes a local MCP server that LM Studio can connect to — enabling natural language queries about your investment portfolios.

![Status Dashboard](screenshots/concept.png)

---

## šŸ“ø Screenshots

**Status Dashboard**

The browser UI shows the current OAuth token and Parqet session status, plus a live log of all tool calls made by LM Studio.

![Status Dashboard](screenshots/dashboard.png)

**LM Studio Integration**

All five Parqet tools are available directly in LM Studio's chat interface.

![LM Studio Tools](screenshots/lmstudio_tools.png)

---

## šŸ›  Project Structure

```
parqet-mcp-broker/
│
ā”œā”€ā”€ app_mcp_real.py       # Main application – Flask broker
ā”œā”€ā”€ verifier.txt          # Temporary PKCE verifier (auto-generated)
ā”œā”€ā”€ requirements.txt      # Python dependencies
ā”œā”€ā”€ README.de.md
└── README.md
```

**Key components inside `app_mcp_real.py`:**

| Component | Description |
|---|---|
| `get_parqet_session()` | Builds an authenticated requests session for Parqet MCP |
| `ensure_parqet_initialized()` | Lazily initializes the Parqet MCP session on first use |
| `call_parqet_tool()` | Proxies tool calls to Parqet, with automatic session recovery |
| `MCP_TOOLS` | Tool definitions exposed to LM Studio (name, description, inputSchema) |
| `mcp_server()` | The `/mcp` endpoint – MCP server for LM Studio (GET/SSE + POST/JSON-RPC) |
| `login()` / `callback()` | OAuth 2.0 Authorization Code flow with PKCE |
| `index()` | Browser status dashboard with live tool call log |

---

## šŸ“– Background & API Reference

The **Parqet Connect API** and **Parqet MCP Server** allow developers to programmatically access portfolio data. This broker uses the MCP server at `https://mcp.parqet.com` and authenticates via OAuth 2.0 through Parqet Connect.

**Useful links:**

- [Parqet Developer Hub](https://developer.parqet.com)
- [Parqet MCP Documentation](https://developer.parqet.com/docs/give-ai-portfolio-context-with-the-parqet-mcp)
- [OpenAPI Specification](https://developer.parqet.com/api-spec/current.json)
- [Model Context Protocol (MCP)](https://modelcontextprotocol.io)

**Exposed MCP Tools:**

| Tool | Description |
|---|---|
| `parqet_list_portfolios` | Lists all portfolios with id, name, currency and broker info. Always call first. |
| `parqet_get_user` | Returns user info (userId, state, permissions). |
| `parqet_get_portfolio` | Returns basic metadata for a single portfolio. |
| `parqet_get_activities` | Returns transactions with optional filters (type, asset, holding, pagination). |
| `parqet_get_performance` | Primary analysis tool. Returns holdings with names, XIRR, TTWROR, gains, dividends and valuations. Supports relative and absolute time intervals. |

---

## šŸ“¦ Installation & Setup

### Prerequisites

- Python 3.9+
- A [Parqet](https://parqet.com) account
- A Parqet Developer integration (Client ID + Redirect URI configured)
- [LM Studio](https://lmstudio.ai) with a tool-capable model (recommended: **Qwen3-14B-GGUF** with context length set to **32768**)

### 1. Clone the repository

```bash
git clone https://github.com/joednemesis/parqet-mcp-broker.git
cd parqet-mcp-broker
```

### 2. Install dependencies

```bash
pip install flask requests
```

Or with a requirements file:

```bash
pip install -r requirements.txt
```

### 3. Configure your Client ID

Open `app_mcp_real.py` and replace the placeholder with your own Client ID from the [Parqet Developer Console](https://developer.parqet.com):

```python
CLIENT_ID = "your-client-id-here"
```

Make sure your integration has `http://localhost:3000/callback` configured as a Redirect URI.

### 4. Configure LM Studio

Add the broker as an MCP server in LM Studio's `mcp.json`:

```json
{
  "mcpServers": {
    "parqet-broker": {
      "url": "http://localhost:3000/mcp"
    }
  }
}
```

Set the model's **context length to at least 16384** (32768 recommended) to handle full Parqet API responses without truncation.

---

## 🚦 Usage

### 1. Start the broker

```bash
python app_mcp_real.py
```

The broker starts at `http://localhost:3000`.

### 2. Authenticate

Open `http://localhost:3000` in your browser and click **Start Authentication**. You will be redirected to Parqet to authorize access. After login, the OAuth token is stored in memory and the status dashboard will confirm the connection.

### 3. Connect LM Studio

Enable the `parqet-broker` MCP server in LM Studio and load a tool-capable model. Start a new chat and ask questions like:

- *"Which portfolios do I have?"*
- *"Show me the holdings and current value of my Trade Republic portfolio."*
- *"How much dividend income did I receive this year?"*
- *"What is my annualized return across all portfolios?"*
- *"Show me all my stock purchases in the last 3 months."*

### Recommended System Prompt for LM Studio

```
You are a financial assistant with access to Parqet portfolio data via MCP tools.

Rules:
1. Call parqet_list_portfolios ONCE to retrieve portfolio IDs.
2. Then call the appropriate tool ONCE with the retrieved ID.
3. Answer immediately after – no further tool calls needed.
4. Only output data you received directly from the tools.
5. Never invent names, prices or any financial information.
6. If something is not in the tool data, state: "This information is not available."
```

---

## šŸ”’ Security Notes

- **The OAuth token is stored in memory only** and is lost when the Flask process restarts. Re-authentication via the browser is required after each restart.
- **The PKCE verifier** is written to `verifier.txt` temporarily during the OAuth flow. This file should not be committed to version control (add it to `.gitignore`).
- **The Client ID is hardcoded** in the current prototype version. For production use, move it to an environment variable or config file.
- **No data is persisted** – the activity log and token exist only for the lifetime of the running process.
- All communication with Parqet uses HTTPS/TLS. The local MCP server (`http://localhost:3000`) is intended for local use only and should not be exposed to the public internet.

---

> **Note:** This is a prototype project built for educational and personal use. It is not officially affiliated with Parqet Fintech GmbH or LM Studio. Use it at your own risk. Always review the [Parqet Terms of Service](https://parqet.com) before building applications on top of their API.