iwym-mcp 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iwym_mcp-0.2.0/.gitignore +4 -0
- iwym_mcp-0.2.0/PKG-INFO +116 -0
- iwym_mcp-0.2.0/README.md +104 -0
- iwym_mcp-0.2.0/pyproject.toml +23 -0
- iwym_mcp-0.2.0/src/iwym_mcp/__init__.py +3 -0
- iwym_mcp-0.2.0/src/iwym_mcp/client.py +102 -0
- iwym_mcp-0.2.0/src/iwym_mcp/server.py +552 -0
- iwym_mcp-0.2.0/tests/test_client.py +90 -0
- iwym_mcp-0.2.0/tests/test_server_tools.py +186 -0
- iwym_mcp-0.2.0/uv.lock +829 -0
iwym_mcp-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: iwym-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MCP server for iwym catalog (assets/instruments/tokens) and radar opportunity queries
|
|
5
|
+
Author: cyetstar
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: assets,iwym,mcp,radar
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Requires-Dist: mcp>=1.9.0
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# iwym-mcp
|
|
14
|
+
|
|
15
|
+
stdio MCP server for iwym **catalog maintenance** (assets / instruments / asset_tokens) and **radar opportunity queries** (spreads / funding_opps). Wraps the operator HTTP API. Does not place orders or touch `auto_exec`.
|
|
16
|
+
|
|
17
|
+
Migrated from `mcp/iwym-assets` (Cursor key `iwym-assets` → `iwym`).
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Python 3.11+
|
|
22
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
23
|
+
- Running iwym API (`IWYM_API_BASE_URL`)
|
|
24
|
+
- Operator API token from **Settings → System → OPERATOR API** → `IWYM_OPERATOR_TOKEN`
|
|
25
|
+
|
|
26
|
+
## Connect (Cursor)
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"iwym": {
|
|
32
|
+
"command": "uv",
|
|
33
|
+
"args": [
|
|
34
|
+
"--directory",
|
|
35
|
+
"/ABS/PATH/iwym-next/mcp/iwym",
|
|
36
|
+
"run",
|
|
37
|
+
"iwym-mcp"
|
|
38
|
+
],
|
|
39
|
+
"env": {
|
|
40
|
+
"IWYM_API_BASE_URL": "http://127.0.0.1:8000",
|
|
41
|
+
"IWYM_OPERATOR_TOKEN": "paste-from-settings-system-operator-api"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`IWYM_API_BASE_URL` is the API origin only (no `/api/v1` suffix).
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cd mcp/iwym
|
|
52
|
+
uv sync
|
|
53
|
+
export IWYM_API_BASE_URL=http://127.0.0.1:8000
|
|
54
|
+
export IWYM_OPERATOR_TOKEN=paste-from-settings-system-operator-api
|
|
55
|
+
uv run iwym-mcp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Tools
|
|
59
|
+
|
|
60
|
+
### Assets
|
|
61
|
+
|
|
62
|
+
| Tool | HTTP | Notes |
|
|
63
|
+
|------|------|--------|
|
|
64
|
+
| `list_assets` | `GET /api/v1/assets` | Flat array; includes disabled; each row has `tokens[]` |
|
|
65
|
+
| `get_asset` | `GET /api/v1/assets/{id}` | Includes `tokens[]` — no separate list-tokens tool |
|
|
66
|
+
| `catalog_diff` | `GET /api/v1/assets/catalog-diffs` | `venue` optional; `include_orphans` default false |
|
|
67
|
+
| `create_or_upsert_asset` | `PUT /api/v1/assets/{id}` | Tool default `enabled=false`; does not rewrite existing scalars |
|
|
68
|
+
| `update_asset` | `PATCH /api/v1/assets/{id}` | kind / enabled / display_symbol / oracle / anchor |
|
|
69
|
+
| `set_enabled` | `PATCH /api/v1/assets/{id}` | Radar whitelist toggle only |
|
|
70
|
+
| `soft_disable_asset` | `DELETE /api/v1/assets/{id}` | `enabled=false`; keeps row |
|
|
71
|
+
|
|
72
|
+
Asset `kind`: `spot_crypto` · `stable` · `wrapped` · `leveraged_token` · `equity`.
|
|
73
|
+
|
|
74
|
+
### Instruments
|
|
75
|
+
|
|
76
|
+
| Tool | HTTP |
|
|
77
|
+
|------|------|
|
|
78
|
+
| `list_asset_instruments` | `GET /api/v1/assets/{id}/instruments` |
|
|
79
|
+
| `search_instruments` | `GET /api/v1/exchanges/instruments/search` |
|
|
80
|
+
| `link_instrument` | `PATCH /api/v1/exchanges/instruments/{id}/link` |
|
|
81
|
+
| `sync_instruments` | `POST /api/v1/exchanges/instruments/sync` (hits upstream; heavy) |
|
|
82
|
+
|
|
83
|
+
### Tokens
|
|
84
|
+
|
|
85
|
+
| Tool | HTTP |
|
|
86
|
+
|------|------|
|
|
87
|
+
| `create_asset_token` | `POST /api/v1/assets/{id}/tokens` |
|
|
88
|
+
| `update_asset_token` | `PATCH /api/v1/assets/{id}/tokens/{chain}/{address}` |
|
|
89
|
+
| `delete_asset_token` | `DELETE …` |
|
|
90
|
+
| `reassign_asset_token` | `POST /api/v1/assets/tokens/reassign` |
|
|
91
|
+
| `migrate_asset_token` | `POST /api/v1/assets/tokens/migrate` |
|
|
92
|
+
| `lookup_asset_tokens` | `POST /api/v1/assets/token-lookups` |
|
|
93
|
+
|
|
94
|
+
Token write fields: `chain_key` · `address` · `symbol` · `decimals` · `status` (`trading`\|`offline`) · `enabled`.
|
|
95
|
+
|
|
96
|
+
### Radar opportunities (read-only)
|
|
97
|
+
|
|
98
|
+
| Tool | HTTP |
|
|
99
|
+
|------|------|
|
|
100
|
+
| `list_spreads` | `GET /api/v1/radar/spreads` |
|
|
101
|
+
| `list_funding_opps` | `GET /api/v1/radar/funding-opps` |
|
|
102
|
+
|
|
103
|
+
Default `limit=100`, max `300`. Filters mirror the Console Radar boards (kind/mode, q, venues, sort, …).
|
|
104
|
+
|
|
105
|
+
## Suggested catalog loop
|
|
106
|
+
|
|
107
|
+
1. `catalog_diff(venue="binance")`.
|
|
108
|
+
2. For one `missing` entry: check aliases / leverage / equity before writing.
|
|
109
|
+
3. `create_or_upsert_asset(..., enabled=false)`.
|
|
110
|
+
4. Add chain contracts with `create_asset_token` when needed; link CEX rows via Sync or `link_instrument`.
|
|
111
|
+
5. Enable with `set_enabled` only when the human wants it on the Radar scan set.
|
|
112
|
+
|
|
113
|
+
## Security
|
|
114
|
+
|
|
115
|
+
- Never commit `IWYM_OPERATOR_TOKEN`.
|
|
116
|
+
- Token has operator powers (whitelist / instruments / radar reads); not a trading key.
|
iwym_mcp-0.2.0/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# iwym-mcp
|
|
2
|
+
|
|
3
|
+
stdio MCP server for iwym **catalog maintenance** (assets / instruments / asset_tokens) and **radar opportunity queries** (spreads / funding_opps). Wraps the operator HTTP API. Does not place orders or touch `auto_exec`.
|
|
4
|
+
|
|
5
|
+
Migrated from `mcp/iwym-assets` (Cursor key `iwym-assets` → `iwym`).
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Python 3.11+
|
|
10
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
11
|
+
- Running iwym API (`IWYM_API_BASE_URL`)
|
|
12
|
+
- Operator API token from **Settings → System → OPERATOR API** → `IWYM_OPERATOR_TOKEN`
|
|
13
|
+
|
|
14
|
+
## Connect (Cursor)
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"iwym": {
|
|
20
|
+
"command": "uv",
|
|
21
|
+
"args": [
|
|
22
|
+
"--directory",
|
|
23
|
+
"/ABS/PATH/iwym-next/mcp/iwym",
|
|
24
|
+
"run",
|
|
25
|
+
"iwym-mcp"
|
|
26
|
+
],
|
|
27
|
+
"env": {
|
|
28
|
+
"IWYM_API_BASE_URL": "http://127.0.0.1:8000",
|
|
29
|
+
"IWYM_OPERATOR_TOKEN": "paste-from-settings-system-operator-api"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`IWYM_API_BASE_URL` is the API origin only (no `/api/v1` suffix).
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cd mcp/iwym
|
|
40
|
+
uv sync
|
|
41
|
+
export IWYM_API_BASE_URL=http://127.0.0.1:8000
|
|
42
|
+
export IWYM_OPERATOR_TOKEN=paste-from-settings-system-operator-api
|
|
43
|
+
uv run iwym-mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Tools
|
|
47
|
+
|
|
48
|
+
### Assets
|
|
49
|
+
|
|
50
|
+
| Tool | HTTP | Notes |
|
|
51
|
+
|------|------|--------|
|
|
52
|
+
| `list_assets` | `GET /api/v1/assets` | Flat array; includes disabled; each row has `tokens[]` |
|
|
53
|
+
| `get_asset` | `GET /api/v1/assets/{id}` | Includes `tokens[]` — no separate list-tokens tool |
|
|
54
|
+
| `catalog_diff` | `GET /api/v1/assets/catalog-diffs` | `venue` optional; `include_orphans` default false |
|
|
55
|
+
| `create_or_upsert_asset` | `PUT /api/v1/assets/{id}` | Tool default `enabled=false`; does not rewrite existing scalars |
|
|
56
|
+
| `update_asset` | `PATCH /api/v1/assets/{id}` | kind / enabled / display_symbol / oracle / anchor |
|
|
57
|
+
| `set_enabled` | `PATCH /api/v1/assets/{id}` | Radar whitelist toggle only |
|
|
58
|
+
| `soft_disable_asset` | `DELETE /api/v1/assets/{id}` | `enabled=false`; keeps row |
|
|
59
|
+
|
|
60
|
+
Asset `kind`: `spot_crypto` · `stable` · `wrapped` · `leveraged_token` · `equity`.
|
|
61
|
+
|
|
62
|
+
### Instruments
|
|
63
|
+
|
|
64
|
+
| Tool | HTTP |
|
|
65
|
+
|------|------|
|
|
66
|
+
| `list_asset_instruments` | `GET /api/v1/assets/{id}/instruments` |
|
|
67
|
+
| `search_instruments` | `GET /api/v1/exchanges/instruments/search` |
|
|
68
|
+
| `link_instrument` | `PATCH /api/v1/exchanges/instruments/{id}/link` |
|
|
69
|
+
| `sync_instruments` | `POST /api/v1/exchanges/instruments/sync` (hits upstream; heavy) |
|
|
70
|
+
|
|
71
|
+
### Tokens
|
|
72
|
+
|
|
73
|
+
| Tool | HTTP |
|
|
74
|
+
|------|------|
|
|
75
|
+
| `create_asset_token` | `POST /api/v1/assets/{id}/tokens` |
|
|
76
|
+
| `update_asset_token` | `PATCH /api/v1/assets/{id}/tokens/{chain}/{address}` |
|
|
77
|
+
| `delete_asset_token` | `DELETE …` |
|
|
78
|
+
| `reassign_asset_token` | `POST /api/v1/assets/tokens/reassign` |
|
|
79
|
+
| `migrate_asset_token` | `POST /api/v1/assets/tokens/migrate` |
|
|
80
|
+
| `lookup_asset_tokens` | `POST /api/v1/assets/token-lookups` |
|
|
81
|
+
|
|
82
|
+
Token write fields: `chain_key` · `address` · `symbol` · `decimals` · `status` (`trading`\|`offline`) · `enabled`.
|
|
83
|
+
|
|
84
|
+
### Radar opportunities (read-only)
|
|
85
|
+
|
|
86
|
+
| Tool | HTTP |
|
|
87
|
+
|------|------|
|
|
88
|
+
| `list_spreads` | `GET /api/v1/radar/spreads` |
|
|
89
|
+
| `list_funding_opps` | `GET /api/v1/radar/funding-opps` |
|
|
90
|
+
|
|
91
|
+
Default `limit=100`, max `300`. Filters mirror the Console Radar boards (kind/mode, q, venues, sort, …).
|
|
92
|
+
|
|
93
|
+
## Suggested catalog loop
|
|
94
|
+
|
|
95
|
+
1. `catalog_diff(venue="binance")`.
|
|
96
|
+
2. For one `missing` entry: check aliases / leverage / equity before writing.
|
|
97
|
+
3. `create_or_upsert_asset(..., enabled=false)`.
|
|
98
|
+
4. Add chain contracts with `create_asset_token` when needed; link CEX rows via Sync or `link_instrument`.
|
|
99
|
+
5. Enable with `set_enabled` only when the human wants it on the Radar scan set.
|
|
100
|
+
|
|
101
|
+
## Security
|
|
102
|
+
|
|
103
|
+
- Never commit `IWYM_OPERATOR_TOKEN`.
|
|
104
|
+
- Token has operator powers (whitelist / instruments / radar reads); not a trading key.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "iwym-mcp"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "MCP server for iwym catalog (assets/instruments/tokens) and radar opportunity queries"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "cyetstar" }]
|
|
9
|
+
keywords = ["mcp", "iwym", "assets", "radar"]
|
|
10
|
+
dependencies = [
|
|
11
|
+
"mcp>=1.9.0",
|
|
12
|
+
"httpx>=0.27.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
iwym-mcp = "iwym_mcp.server:main"
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["hatchling"]
|
|
20
|
+
build-backend = "hatchling.build"
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["src/iwym_mcp"]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""HTTP client for the iwym operator API (assets / exchanges / radar)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
ASSETS_PREFIX = "/api/v1/assets"
|
|
10
|
+
EXCHANGES_PREFIX = "/api/v1/exchanges"
|
|
11
|
+
RADAR_PREFIX = "/api/v1/radar"
|
|
12
|
+
|
|
13
|
+
# Back-compat alias used by older tests / docs.
|
|
14
|
+
API_PREFIX = ASSETS_PREFIX
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class IwymApiError(Exception):
|
|
18
|
+
def __init__(self, status_code: int, detail: object):
|
|
19
|
+
self.status_code = status_code
|
|
20
|
+
self.detail = detail
|
|
21
|
+
super().__init__(f"{status_code}: {detail}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class IwymApiClient:
|
|
25
|
+
def __init__(self, base_url: str, token: str, *, timeout: float = 120.0):
|
|
26
|
+
self._base = base_url.rstrip("/")
|
|
27
|
+
self._token = token
|
|
28
|
+
self._timeout = timeout
|
|
29
|
+
|
|
30
|
+
def _full_path(self, path: str) -> str:
|
|
31
|
+
"""Resolve a relative assets path or absolute ``/api/…`` path."""
|
|
32
|
+
if path.startswith("/api/"):
|
|
33
|
+
return path
|
|
34
|
+
if path in ("", "/"):
|
|
35
|
+
return ASSETS_PREFIX
|
|
36
|
+
if not path.startswith("/"):
|
|
37
|
+
path = f"/{path}"
|
|
38
|
+
return f"{ASSETS_PREFIX}{path}"
|
|
39
|
+
|
|
40
|
+
async def request(
|
|
41
|
+
self,
|
|
42
|
+
method: str,
|
|
43
|
+
path: str,
|
|
44
|
+
*,
|
|
45
|
+
json: Any | None = None,
|
|
46
|
+
params: dict[str, Any] | None = None,
|
|
47
|
+
) -> Any:
|
|
48
|
+
async with httpx.AsyncClient(base_url=self._base, timeout=self._timeout) as client:
|
|
49
|
+
response = await client.request(
|
|
50
|
+
method,
|
|
51
|
+
self._full_path(path),
|
|
52
|
+
headers={"Authorization": f"Bearer {self._token}"},
|
|
53
|
+
json=json,
|
|
54
|
+
params=params,
|
|
55
|
+
)
|
|
56
|
+
if response.status_code >= 400:
|
|
57
|
+
raise IwymApiError(response.status_code, _error_detail(response))
|
|
58
|
+
if response.status_code == 204 or not response.content:
|
|
59
|
+
return None
|
|
60
|
+
return response.json()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def patch_asset_body(
|
|
64
|
+
*,
|
|
65
|
+
display_symbol: str | None = None,
|
|
66
|
+
kind: str | None = None,
|
|
67
|
+
oracle_feed_type: str | None = None,
|
|
68
|
+
anchor_asset_id: str | None = None,
|
|
69
|
+
enabled: bool | None = None,
|
|
70
|
+
include_anchor: bool = False,
|
|
71
|
+
) -> dict[str, Any]:
|
|
72
|
+
"""Build a PATCH body. Omitted / None fields are left unchanged server-side.
|
|
73
|
+
|
|
74
|
+
Pass ``include_anchor=True`` with ``anchor_asset_id=None`` to clear the
|
|
75
|
+
anchor (send JSON null). Otherwise a None anchor is not sent.
|
|
76
|
+
"""
|
|
77
|
+
body: dict[str, Any] = {}
|
|
78
|
+
if display_symbol is not None:
|
|
79
|
+
body["display_symbol"] = display_symbol
|
|
80
|
+
if kind is not None:
|
|
81
|
+
body["kind"] = kind
|
|
82
|
+
if oracle_feed_type is not None:
|
|
83
|
+
body["oracle_feed_type"] = oracle_feed_type
|
|
84
|
+
if enabled is not None:
|
|
85
|
+
body["enabled"] = enabled
|
|
86
|
+
if include_anchor:
|
|
87
|
+
body["anchor_asset_id"] = anchor_asset_id
|
|
88
|
+
elif anchor_asset_id is not None:
|
|
89
|
+
body["anchor_asset_id"] = anchor_asset_id
|
|
90
|
+
return body
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _error_detail(response: httpx.Response) -> object:
|
|
94
|
+
try:
|
|
95
|
+
body = response.json()
|
|
96
|
+
except ValueError:
|
|
97
|
+
return response.text
|
|
98
|
+
if isinstance(body, dict) and isinstance(body.get("error"), dict):
|
|
99
|
+
return body["error"]
|
|
100
|
+
if isinstance(body, dict) and "detail" in body:
|
|
101
|
+
return body["detail"]
|
|
102
|
+
return body
|