codal-mcp 0.2.0__tar.gz → 0.2.1__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.
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/workflows/ci.yml +1 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/workflows/publish.yml +1 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/PKG-INFO +1 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/pyproject.toml +1 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/server.json +2 -2
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/src/codal_mcp/http.py +6 -4
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/src/codal_mcp/server.py +18 -2
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/test_codal.py +26 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/uv.lock +1 -1
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/banner.png +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.github/dependabot.yml +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/.gitignore +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/LICENSE +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/README.md +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/src/codal_mcp/__init__.py +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/src/codal_mcp/codal.py +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/src/codal_mcp/registry.py +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/conftest.py +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/attachment_1618277.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/attachment_1618277_curl.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/categories.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/companies_trim.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/decision_1612323.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/decision_1612323_sheet0.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/decision_1618277.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/decision_captcha_wall.html +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/financial_years_foolad.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/industry_groups.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/search_foolad.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/search_tracing_1612323.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/fixtures/search_tracing_1618277.json +0 -0
- {codal_mcp-0.2.0 → codal_mcp-0.2.1}/tests/test_live_codal.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codal-mcp
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Unofficial read-only MCP server for codal.ir (کدال): disclosures, letters and financial statements of Iranian listed companies.
|
|
5
5
|
Project-URL: Homepage, https://github.com/sepehr071/codal-mcp
|
|
6
6
|
Project-URL: Issues, https://github.com/sepehr071/codal-mcp/issues
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://github.com/sepehr071/codal-mcp",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.1",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"registryBaseUrl": "https://pypi.org",
|
|
16
16
|
"identifier": "codal-mcp",
|
|
17
|
-
"version": "0.2.
|
|
17
|
+
"version": "0.2.1",
|
|
18
18
|
"runtimeHint": "uvx",
|
|
19
19
|
"transport": {
|
|
20
20
|
"type": "stdio"
|
|
@@ -45,7 +45,7 @@ PAGE_HEADERS = {
|
|
|
45
45
|
MIN_INTERVAL = 2.0 # seconds between two requests to codal.ir; all requests are serialized
|
|
46
46
|
JITTER = (0.1, 0.5) # extra seconds added to each gap
|
|
47
47
|
BLOCK_COOLDOWN = 60 # seconds to stop calling codal.ir after a 429 or captcha (shared servers recover fast)
|
|
48
|
-
MAX_RETRIES = 1 # timeouts, network errors and 5xx only; 429 and 403 are never retried
|
|
48
|
+
MAX_RETRIES = 1 # read timeouts, network errors and 5xx only; connect timeouts, 429 and 403 are never retried
|
|
49
49
|
RETRY_DELAY = 2.0 # seconds before the retry
|
|
50
50
|
CACHE_TTL = 120 # seconds; default for searches
|
|
51
51
|
CACHE_MAX = 64
|
|
@@ -118,7 +118,7 @@ def _next_proxy(client: httpx.AsyncClient) -> bool:
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
async def _close_later(client: httpx.AsyncClient) -> None:
|
|
121
|
-
await asyncio.sleep(40) # longer than the
|
|
121
|
+
await asyncio.sleep(40) # longer than any request (the tool DEADLINE is 15 s)
|
|
122
122
|
await client.aclose()
|
|
123
123
|
|
|
124
124
|
|
|
@@ -140,7 +140,7 @@ def _get_client() -> httpx.AsyncClient:
|
|
|
140
140
|
max_connections=4,
|
|
141
141
|
),
|
|
142
142
|
headers=HEADERS,
|
|
143
|
-
timeout=httpx.Timeout(
|
|
143
|
+
timeout=httpx.Timeout(10, connect=4), # answers take 0.3-4 s; keeps a retry within the tool DEADLINE
|
|
144
144
|
limits=httpx.Limits(max_connections=4),
|
|
145
145
|
follow_redirects=False,
|
|
146
146
|
trust_env=False,
|
|
@@ -179,7 +179,9 @@ async def fetch(url: str, params: dict[str, Any] | None = None, text: bool = Fal
|
|
|
179
179
|
try:
|
|
180
180
|
r, content, client = await _request(url, query, headers, host)
|
|
181
181
|
except ApiError as e:
|
|
182
|
-
|
|
182
|
+
# A connect timeout is codal.ir ignoring this IP (it hangs for non-Iranian ones): a retry only waits again.
|
|
183
|
+
# curl_cffi raises a plain TimeoutException for both kinds, so its message tells them apart.
|
|
184
|
+
if last or e.status is not None or "Connection timed out" in str(e.__cause__):
|
|
183
185
|
raise
|
|
184
186
|
await asyncio.sleep(RETRY_DELAY)
|
|
185
187
|
continue
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""MCP server entry point: registers every read-only codal.ir tool."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import functools
|
|
4
5
|
import inspect
|
|
5
6
|
import json
|
|
@@ -9,8 +10,13 @@ from mcp.server import MCPServer
|
|
|
9
10
|
from mcp.types import ToolAnnotations
|
|
10
11
|
|
|
11
12
|
from . import __version__, codal # noqa: F401 (imports register the tools)
|
|
13
|
+
from .http import ApiError
|
|
12
14
|
from .registry import TOOLS
|
|
13
15
|
|
|
16
|
+
# Seconds one tool call may take, waiting for the request queue and retries included: hosts like the mcpfarsi router
|
|
17
|
+
# cut a call at 20 s, and a clear error before that lets them retry elsewhere.
|
|
18
|
+
DEADLINE = 15
|
|
19
|
+
|
|
14
20
|
INSTRUCTIONS = """\
|
|
15
21
|
Unofficial, read-only access to codal.ir (سامانه کدال), the disclosure system of Iranian listed companies:
|
|
16
22
|
financial statements, monthly reports, meeting decisions, dividends, capital increases, material news.
|
|
@@ -48,11 +54,21 @@ def _slim(v, top=False):
|
|
|
48
54
|
|
|
49
55
|
|
|
50
56
|
def compact(fn):
|
|
51
|
-
"""Return the tool result as one compact JSON text block (the SDK default sends it twice, indented).
|
|
57
|
+
"""Return the tool result as one compact JSON text block (the SDK default sends it twice, indented).
|
|
58
|
+
|
|
59
|
+
The call fails with ApiError once it runs past DEADLINE.
|
|
60
|
+
"""
|
|
52
61
|
|
|
53
62
|
@functools.wraps(fn)
|
|
54
63
|
async def run(*args, **kwargs):
|
|
55
|
-
|
|
64
|
+
try:
|
|
65
|
+
result = await asyncio.wait_for(fn(*args, **kwargs), DEADLINE)
|
|
66
|
+
except asyncio.TimeoutError:
|
|
67
|
+
raise ApiError(
|
|
68
|
+
f"codal.ir did not answer within {DEADLINE} s. It often answers only Iranian connections "
|
|
69
|
+
"(CODAL_MCP_PROXY sets an Iranian proxy). Try again in a moment."
|
|
70
|
+
) from None
|
|
71
|
+
return json.dumps(_slim(result, top=True), ensure_ascii=False, separators=(",", ":"))
|
|
56
72
|
|
|
57
73
|
run.__doc__ = inspect.cleandoc(fn.__doc__ or "")
|
|
58
74
|
return run
|
|
@@ -4,7 +4,7 @@ import httpx
|
|
|
4
4
|
import pytest
|
|
5
5
|
from conftest import FIXTURES, fixture, page
|
|
6
6
|
|
|
7
|
-
from codal_mcp import http
|
|
7
|
+
from codal_mcp import http, server
|
|
8
8
|
|
|
9
9
|
pytestmark = pytest.mark.anyio
|
|
10
10
|
|
|
@@ -233,3 +233,28 @@ async def test_server_error_is_retried_once(client, api):
|
|
|
233
233
|
api[Q] = flaky
|
|
234
234
|
r = await client.call_tool("cd_search_letters", {})
|
|
235
235
|
assert not r.is_error and len(calls) == 2
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
async def test_connect_timeout_is_not_retried_but_read_timeout_is(client, api):
|
|
239
|
+
def hang(request):
|
|
240
|
+
raise httpx.TimeoutException("Failed to perform, curl: (28) Connection timed out after 4010 milliseconds.")
|
|
241
|
+
|
|
242
|
+
api[Q] = hang
|
|
243
|
+
r = await client.call_tool("cd_search_letters", {})
|
|
244
|
+
assert r.is_error and "did not answer in time" in r.content[0].text and len(api.calls) == 1
|
|
245
|
+
|
|
246
|
+
def slow(request):
|
|
247
|
+
raise httpx.TimeoutException("Failed to perform, curl: (28) Operation timed out after 14000 milliseconds.")
|
|
248
|
+
|
|
249
|
+
api[Q] = slow
|
|
250
|
+
await client.call_tool("cd_search_letters", {"page": 2})
|
|
251
|
+
assert len(api.calls) == 3
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
async def test_call_past_deadline_fails_with_clear_error(client, api, monkeypatch):
|
|
255
|
+
monkeypatch.setattr(server, "DEADLINE", 0.2)
|
|
256
|
+
monkeypatch.setattr(http, "MIN_INTERVAL", 1) # the second request waits in the queue past the deadline
|
|
257
|
+
api[Q] = by_tracing
|
|
258
|
+
serve_letters(api)
|
|
259
|
+
r = await client.call_tool("cd_letter", {"tracing_no": 1618277})
|
|
260
|
+
assert r.is_error and "did not answer within 0.2 s" in r.content[0].text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|