cited-cli 0.5.0__tar.gz → 0.5.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.
- {cited_cli-0.5.0 → cited_cli-0.5.1}/PKG-INFO +4 -4
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/pyproject.toml +1 -1
- cited_cli-0.5.1/packages/core/src/cited_core/__init__.py +1 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/README.md +4 -4
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/SKILL.md +3 -3
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/pyproject.toml +2 -2
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/remote.py +56 -2
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tool_changelog.yaml +12 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/_helpers.py +103 -10
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/tests/test_auth_provider.py +41 -32
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/tests/test_plan_gating.py +73 -0
- cited_cli-0.5.1/packages/mcp/tests/test_surface_invariants.py +332 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/tests/test_tools.py +645 -22
- {cited_cli-0.5.0 → cited_cli-0.5.1}/pyproject.toml +4 -4
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/conftest.py +3 -1
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_api_client.py +0 -2
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_auth.py +31 -18
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_config.py +0 -2
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_feature_parity.py +25 -26
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_live_pipeline.py +7 -9
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_mcp_tools.py +39 -20
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_output.py +1 -3
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_pipeline.py +1138 -248
- cited_cli-0.5.0/packages/core/src/cited_core/__init__.py +0 -1
- {cited_cli-0.5.0 → cited_cli-0.5.1}/.github/workflows/changelog-guard.yml +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/.github/workflows/ci.yml +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/.github/workflows/release.yml +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/.gitignore +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/CLAUDE.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/DEMO.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/FUTURE.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/LICENSE +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/README.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/TEST_RUNBOOK.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/.claude-plugin/marketplace.json +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/.claude-plugin/plugin.json +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/.mcp.json +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/CLAUDE_DESKTOP_SETUP.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/agents/geo-analyst.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/commands/audit.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/commands/recommend.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/commands/status.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/settings.json +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/skills/business-setup/SKILL.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/skills/explore/SKILL.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/skills/geo-audit/SKILL.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/cited-plugins/skills/geo-recommend/SKILL.md +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/api/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/api/client.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/api/endpoints.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/auth/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/auth/oauth_server.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/auth/store.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/config/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/config/constants.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/config/manager.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/core/src/cited_core/errors.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/__main__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/auth_provider.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/context.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/plan_gating.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/server.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tool_manager.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/action_plan.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/agent.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/analytics.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/audit.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/auth.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/billing.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/business.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/changelog.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/hq.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/job.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/recommend.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/src/cited_mcp/tools/solution.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/packages/mcp/tests/conftest.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/scripts/dev-install.sh +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/scripts/mcp_test_harness.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/__main__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/api/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/api/client.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/api/endpoints.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/app.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/auth/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/auth/oauth_server.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/auth/store.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/agent.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/analytics.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/audit.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/auth.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/business.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/config_cmd.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/hq.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/job.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/mcp_cmd.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/named_audit.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/recommend.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/commands/solution.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/config/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/config/constants.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/config/manager.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/context.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/server.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/_helpers.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/audit.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/auth.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/business.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/job.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/recommend.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/mcp/tools/solution.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/output/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/output/formatter.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/output/progress.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/output/tables.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/utils/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/utils/errors.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/src/cited_cli/utils/interactive.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/__init__.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_mcp_server.py +0 -0
- {cited_cli-0.5.0 → cited_cli-0.5.1}/tests/test_version.py +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cited-cli
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: CLI for the Cited GEO platform
|
|
5
5
|
Author-email: Cited <support@youcited.com>
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
|
-
Requires-Dist: cited-core>=0.5.
|
|
9
|
+
Requires-Dist: cited-core>=0.5.1
|
|
10
10
|
Requires-Dist: rich>=13.0.0
|
|
11
11
|
Requires-Dist: typer>=0.15.0
|
|
12
12
|
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: cited-mcp>=0.5.
|
|
13
|
+
Requires-Dist: cited-mcp>=0.5.1; extra == 'dev'
|
|
14
14
|
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
15
15
|
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
16
16
|
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
17
17
|
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
18
18
|
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
19
19
|
Provides-Extra: mcp
|
|
20
|
-
Requires-Dist: cited-mcp>=0.5.
|
|
20
|
+
Requires-Dist: cited-mcp>=0.5.1; extra == 'mcp'
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
|
|
23
23
|
# Cited CLI
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.5.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cited-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for the [Cited](https://youcited.com) Generative Engine Optimization (GEO) platform. Exposes
|
|
3
|
+
MCP server for the [Cited](https://youcited.com) Generative Engine Optimization (GEO) platform. Exposes 73 tools that let AI assistants like Claude manage businesses, run GEO audits, generate recommendations, work a prioritized action plan, verify fixes via the Validation Engine, and create solutions — all through the [Model Context Protocol](https://modelcontextprotocol.io/).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -231,9 +231,9 @@ Tools are gated by subscription tier. All tiers can read data; write operations
|
|
|
231
231
|
|
|
232
232
|
| Tier | Tools Available |
|
|
233
233
|
|------|----------------|
|
|
234
|
-
| **Growth** (entry) | Auth, list/get businesses, crawl, health scores, audits (start/status/result/list), all recommendation tools, action-plan reads (get_action_plan, get_quick_wins), Validation Engine reads, job status — **
|
|
235
|
-
| **Scale** | Everything in Growth + create/update/delete businesses, create/update/delete audit templates, all solution tools, batch solutions, export audit, cancel job, action-plan writes (mark_action_done, dismiss_action, get_action_progress) — **
|
|
236
|
-
| **Pro** | Everything in Scale + usage stats, HQ dashboard, analytics, agent API — **
|
|
234
|
+
| **Growth** (entry) | Auth, list/get businesses, crawl, health scores, audits (start/status/result/list), all recommendation tools, action-plan reads (get_action_plan, get_quick_wins), Validation Engine reads, job status — **31 tools** |
|
|
235
|
+
| **Scale** | Everything in Growth + create/update/delete businesses, create/update/delete audit templates, all solution tools, batch solutions, export audit, cancel job, action-plan writes (mark_action_done, dismiss_action, get_action_progress) — **62 tools** |
|
|
236
|
+
| **Pro** | Everything in Scale + usage stats, HQ dashboard, analytics, agent API — **73 tools** |
|
|
237
237
|
|
|
238
238
|
When a user calls a tool above their plan, the server returns a structured error with an upgrade link:
|
|
239
239
|
|
|
@@ -50,9 +50,9 @@ The typical flow is: **Business Setup → Audit → Recommendations → Solution
|
|
|
50
50
|
|
|
51
51
|
Tools are gated by subscription tier. If a tool is above the user's plan, it returns an upgrade message with a billing link.
|
|
52
52
|
|
|
53
|
-
- **Growth** (entry tier): Read-only — list/get businesses, run audits, view recommendations (
|
|
54
|
-
- **Scale**: Full write access — create/update/delete, solutions, export, cancel (
|
|
55
|
-
- **Pro**: Everything + HQ dashboard, analytics, agent API (
|
|
53
|
+
- **Growth** (entry tier): Read-only — list/get businesses, run audits, view recommendations (31 tools)
|
|
54
|
+
- **Scale**: Full write access — create/update/delete, solutions, export, cancel (62 tools)
|
|
55
|
+
- **Pro**: Everything + HQ dashboard, analytics, agent API (73 tools)
|
|
56
56
|
|
|
57
57
|
Always call `check_auth_status` first — it shows the user's plan and remaining limits.
|
|
58
58
|
|
|
@@ -4,14 +4,14 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cited-mcp"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.1"
|
|
8
8
|
description = "MCP server for the Cited GEO platform"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "LicenseRef-Proprietary"
|
|
11
11
|
requires-python = ">=3.11"
|
|
12
12
|
authors = [{ name = "Cited", email = "support@youcited.com" }]
|
|
13
13
|
dependencies = [
|
|
14
|
-
"cited-core>=0.5.
|
|
14
|
+
"cited-core>=0.5.1",
|
|
15
15
|
"mcp>=1.27.0",
|
|
16
16
|
"PyJWT>=2.8.0",
|
|
17
17
|
"PyYAML>=6.0",
|
|
@@ -204,6 +204,56 @@ class _OAuthEventLogMiddleware:
|
|
|
204
204
|
logger.info("[oauth-event] %s", kv)
|
|
205
205
|
|
|
206
206
|
|
|
207
|
+
class _RequestContextMiddleware:
|
|
208
|
+
"""ASGI middleware that captures the request's source IP and User-Agent
|
|
209
|
+
into contextvars consumed by the tool-call decorator.
|
|
210
|
+
|
|
211
|
+
Why: ``tool_call`` log lines previously carried no source-identifying
|
|
212
|
+
metadata beyond the (possibly absent) decoded user JWT. When a probe
|
|
213
|
+
came in with a non-standard token — logged as user=``unknown`` — there
|
|
214
|
+
was no way to trace the source. Threading an HTTP request object
|
|
215
|
+
through every tool function is invasive; contextvars stay scoped to
|
|
216
|
+
the request's async task without touching tool signatures.
|
|
217
|
+
|
|
218
|
+
For stdio transport this middleware is not in the chain, so the
|
|
219
|
+
contextvars stay None and the log fields render as null.
|
|
220
|
+
|
|
221
|
+
We prefer the leftmost value of ``X-Forwarded-For`` when present
|
|
222
|
+
because the ALB inserts the original client IP there and the immediate
|
|
223
|
+
``scope["client"]`` is the ALB's internal address. Trusting X-F-F is
|
|
224
|
+
only safe behind a known proxy — which is the deploy topology here.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
def __init__(self, app: ASGIApp) -> None:
|
|
228
|
+
self.app = app
|
|
229
|
+
|
|
230
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
231
|
+
if scope["type"] != "http":
|
|
232
|
+
await self.app(scope, receive, send)
|
|
233
|
+
return
|
|
234
|
+
|
|
235
|
+
from cited_mcp.tools._helpers import _request_ip, _request_ua
|
|
236
|
+
|
|
237
|
+
headers = {k: v for k, v in scope.get("headers", [])}
|
|
238
|
+
xff = headers.get(b"x-forwarded-for", b"").decode("latin-1", errors="replace")
|
|
239
|
+
if xff:
|
|
240
|
+
ip: str | None = xff.split(",")[0].strip() or None
|
|
241
|
+
else:
|
|
242
|
+
client = scope.get("client") or ("?", 0)
|
|
243
|
+
ip = client[0] if client and client[0] != "?" else None
|
|
244
|
+
|
|
245
|
+
ua_bytes = headers.get(b"user-agent", b"")
|
|
246
|
+
ua = ua_bytes.decode("latin-1", errors="replace")[:120] if ua_bytes else None
|
|
247
|
+
|
|
248
|
+
token_ip = _request_ip.set(ip)
|
|
249
|
+
token_ua = _request_ua.set(ua)
|
|
250
|
+
try:
|
|
251
|
+
await self.app(scope, receive, send)
|
|
252
|
+
finally:
|
|
253
|
+
_request_ip.reset(token_ip)
|
|
254
|
+
_request_ua.reset(token_ua)
|
|
255
|
+
|
|
256
|
+
|
|
207
257
|
@asynccontextmanager
|
|
208
258
|
async def cited_remote_lifespan(server: FastMCP) -> AsyncIterator[CitedContext]:
|
|
209
259
|
"""Lifespan for the remote MCP server.
|
|
@@ -403,9 +453,13 @@ def run_remote_server() -> None:
|
|
|
403
453
|
starlette_app = server.streamable_http_app()
|
|
404
454
|
# Order: oauth-event log on the OUTSIDE of the registration patcher so
|
|
405
455
|
# patcher-rejected /register calls (400 invalid_redirect_uri) still
|
|
406
|
-
# produce an event line.
|
|
456
|
+
# produce an event line. RequestContextMiddleware sits innermost so
|
|
457
|
+
# its contextvars (ip, user_agent) are set in the same task that
|
|
458
|
+
# dispatches the tool call.
|
|
407
459
|
patched_app = _OAuthEventLogMiddleware(
|
|
408
|
-
_PatchRegistrationMiddleware(
|
|
460
|
+
_PatchRegistrationMiddleware(
|
|
461
|
+
_RequestContextMiddleware(starlette_app)
|
|
462
|
+
)
|
|
409
463
|
)
|
|
410
464
|
|
|
411
465
|
config = uvicorn.Config(
|
|
@@ -21,6 +21,18 @@
|
|
|
21
21
|
# this file.
|
|
22
22
|
|
|
23
23
|
versions:
|
|
24
|
+
- version: "0.5.1"
|
|
25
|
+
released: "2026-05-18"
|
|
26
|
+
# Telemetry-only release: tool surface is unchanged (fingerprint matches
|
|
27
|
+
# 0.5.0). Adds forensic fields to every tool_call log line — ip,
|
|
28
|
+
# user_agent, and a new auth_kind discriminator (anonymous / agent_key /
|
|
29
|
+
# oauth_email / oauth_no_email / oauth_malformed / stdio_email /
|
|
30
|
+
# stdio_no_email / stdio_malformed). Also fixes client_id extraction
|
|
31
|
+
# which was reading from user_jwt claims (always null in prod) instead
|
|
32
|
+
# of the OAuth access token. Motivated by a 2026-05-02 dev probe that
|
|
33
|
+
# logged user=unknown with no traceable source.
|
|
34
|
+
fingerprint: "5bef45100c53"
|
|
35
|
+
|
|
24
36
|
- version: "0.5.0"
|
|
25
37
|
released: "2026-05-11"
|
|
26
38
|
# Three new read-only list_* tools to enable persona/product/buyer-intent
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import contextlib
|
|
4
|
+
import contextvars
|
|
4
5
|
import functools
|
|
5
6
|
import hashlib
|
|
6
7
|
import json
|
|
@@ -22,6 +23,20 @@ from cited_mcp.context import CitedContext
|
|
|
22
23
|
|
|
23
24
|
logger = logging.getLogger("cited_mcp.usage")
|
|
24
25
|
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
# Per-request forensic context (set by remote.py _RequestContextMiddleware).
|
|
28
|
+
#
|
|
29
|
+
# These let tool_call log lines carry the request's source IP and User-Agent
|
|
30
|
+
# without threading an HTTP request object through every tool function. For
|
|
31
|
+
# stdio transport (no HTTP) they remain None and are emitted as null in logs.
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
_request_ip: contextvars.ContextVar[str | None] = contextvars.ContextVar(
|
|
34
|
+
"cited_mcp_request_ip", default=None
|
|
35
|
+
)
|
|
36
|
+
_request_ua: contextvars.ContextVar[str | None] = contextvars.ContextVar(
|
|
37
|
+
"cited_mcp_request_ua", default=None
|
|
38
|
+
)
|
|
39
|
+
|
|
25
40
|
# ---------------------------------------------------------------------------
|
|
26
41
|
# Response size guardrails
|
|
27
42
|
# ---------------------------------------------------------------------------
|
|
@@ -244,18 +259,84 @@ def _extract_user(token: str | None) -> str:
|
|
|
244
259
|
return "unknown"
|
|
245
260
|
|
|
246
261
|
|
|
247
|
-
def
|
|
248
|
-
"""
|
|
249
|
-
|
|
262
|
+
def _extract_client_id_from_oauth() -> str | None:
|
|
263
|
+
"""Return the OAuth client_id from the current access token, truncated.
|
|
264
|
+
|
|
265
|
+
The MCP server's client_id is itself a signed JWT (RFC 7591 dynamic
|
|
266
|
+
registration encoded into the id), so we truncate to a 12-char prefix
|
|
267
|
+
sufficient to group connector traffic without bloating log lines.
|
|
268
|
+
|
|
269
|
+
Returns None for stdio transport (no OAuth context), or whenever the
|
|
270
|
+
access-token contextvar is unset.
|
|
271
|
+
|
|
272
|
+
Note: this used to decode the user_jwt looking for client_id/aud/azp
|
|
273
|
+
claims, but backend session JWTs do not carry OAuth-client identity —
|
|
274
|
+
so the field was always empty in production logs. This implementation
|
|
275
|
+
reads from the OAuth access token instead.
|
|
276
|
+
"""
|
|
277
|
+
try:
|
|
278
|
+
from mcp.server.auth.middleware.auth_context import get_access_token
|
|
279
|
+
except ImportError:
|
|
250
280
|
return None
|
|
251
281
|
try:
|
|
252
|
-
|
|
253
|
-
cid = payload.get("client_id") or payload.get("aud") or payload.get("azp")
|
|
254
|
-
if isinstance(cid, list):
|
|
255
|
-
cid = cid[0] if cid else None
|
|
256
|
-
return str(cid) if cid else None
|
|
282
|
+
access_token = get_access_token()
|
|
257
283
|
except Exception:
|
|
258
284
|
return None
|
|
285
|
+
if not access_token:
|
|
286
|
+
return None
|
|
287
|
+
cid = getattr(access_token, "client_id", None)
|
|
288
|
+
if not cid:
|
|
289
|
+
return None
|
|
290
|
+
return str(cid)[:12]
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _extract_auth_kind(
|
|
294
|
+
ctx: Context[Any, CitedContext, Any], token: str | None
|
|
295
|
+
) -> str:
|
|
296
|
+
"""Categorize the auth path for forensic logging.
|
|
297
|
+
|
|
298
|
+
Returns one of:
|
|
299
|
+
- ``anonymous`` — no token, no agent key
|
|
300
|
+
- ``agent_key`` — CitedClient has agent_api_key set (stdio mode)
|
|
301
|
+
- ``oauth_email`` — OAuth flow, user_jwt has email claim
|
|
302
|
+
- ``oauth_no_email`` — OAuth flow, user_jwt decoded but no email
|
|
303
|
+
- ``oauth_malformed`` — OAuth flow, user_jwt couldn't be decoded
|
|
304
|
+
- ``stdio_email`` — stdio mode, token is a JWT with email claim
|
|
305
|
+
- ``stdio_no_email`` — stdio mode, token decoded but no email
|
|
306
|
+
- ``stdio_malformed`` — stdio mode, token isn't a parseable JWT
|
|
307
|
+
|
|
308
|
+
Lets us tell apart the practical cases — including the case where
|
|
309
|
+
``_extract_user`` returns ``"unknown"`` because the token was not a
|
|
310
|
+
JWT at all versus because the JWT had no email/sub claim. Without
|
|
311
|
+
this, the ``<unknown>`` bucket in usage reports is unactionable.
|
|
312
|
+
"""
|
|
313
|
+
try:
|
|
314
|
+
lc = ctx.request_context.lifespan_context
|
|
315
|
+
if getattr(lc.client, "agent_api_key", None):
|
|
316
|
+
return "agent_key"
|
|
317
|
+
except Exception:
|
|
318
|
+
pass
|
|
319
|
+
|
|
320
|
+
method = "stdio"
|
|
321
|
+
try:
|
|
322
|
+
from mcp.server.auth.middleware.auth_context import get_access_token
|
|
323
|
+
|
|
324
|
+
if get_access_token() is not None:
|
|
325
|
+
method = "oauth"
|
|
326
|
+
except Exception:
|
|
327
|
+
pass
|
|
328
|
+
|
|
329
|
+
if not token:
|
|
330
|
+
return "anonymous" if method == "stdio" else "oauth_no_token"
|
|
331
|
+
|
|
332
|
+
try:
|
|
333
|
+
payload = pyjwt.decode(token, options={"verify_signature": False})
|
|
334
|
+
except Exception:
|
|
335
|
+
return f"{method}_malformed"
|
|
336
|
+
|
|
337
|
+
if payload.get("email"):
|
|
338
|
+
return f"{method}_email"
|
|
339
|
+
return f"{method}_no_email"
|
|
259
340
|
|
|
260
341
|
|
|
261
342
|
# ---------------------------------------------------------------------------
|
|
@@ -384,7 +465,8 @@ def log_tool_call(
|
|
|
384
465
|
token = _resolve_token(ctx)
|
|
385
466
|
rl_key = _rate_limit_key(token)
|
|
386
467
|
user = _extract_user(token)
|
|
387
|
-
|
|
468
|
+
auth_kind = _extract_auth_kind(ctx, token)
|
|
469
|
+
client_id = _extract_client_id_from_oauth()
|
|
388
470
|
request_id = uuid.uuid4().hex[:12]
|
|
389
471
|
start = time.monotonic()
|
|
390
472
|
build = _get_build_identity()
|
|
@@ -399,7 +481,10 @@ def log_tool_call(
|
|
|
399
481
|
"request_id": request_id,
|
|
400
482
|
"tool": tool_name,
|
|
401
483
|
"user": user,
|
|
484
|
+
"auth_kind": auth_kind,
|
|
402
485
|
"client_id": client_id,
|
|
486
|
+
"ip": _request_ip.get(),
|
|
487
|
+
"user_agent": _request_ua.get(),
|
|
403
488
|
"server_version": build["server_version"],
|
|
404
489
|
"tools_fingerprint": build["tools_fingerprint"],
|
|
405
490
|
"deployment_id": build["deployment_id"],
|
|
@@ -407,7 +492,15 @@ def log_tool_call(
|
|
|
407
492
|
if resources:
|
|
408
493
|
payload["resources"] = resources
|
|
409
494
|
payload.update(extra)
|
|
410
|
-
|
|
495
|
+
# CodeQL flags this as clear-text logging of sensitive data because
|
|
496
|
+
# `user` is sourced from a JWT email claim. This is by design —
|
|
497
|
+
# operator usage reports (scripts/mcp_usage_report.py) attribute
|
|
498
|
+
# tool calls to users by email, which is necessary for forensics
|
|
499
|
+
# and abuse investigation. Logs flow to a private CloudWatch group
|
|
500
|
+
# with restricted IAM access. Email is not transmitted anywhere
|
|
501
|
+
# else from this line. If we later move to hashed identifiers,
|
|
502
|
+
# the suppression can be removed.
|
|
503
|
+
logger.info(json.dumps(payload, default=str)) # noqa: E501 lgtm[py/clear-text-logging-sensitive-data]
|
|
411
504
|
|
|
412
505
|
# Rate limit check
|
|
413
506
|
if rl_err := _check_rate_limit(rl_key):
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Tests for the CitedOAuthProvider — specifically JWT expiry handling."""
|
|
2
|
+
|
|
2
3
|
from __future__ import annotations
|
|
3
4
|
|
|
4
5
|
import asyncio
|
|
@@ -59,14 +60,16 @@ class TestLoadAccessToken:
|
|
|
59
60
|
def test_rejects_expired_user_jwt(self):
|
|
60
61
|
provider = _make_provider()
|
|
61
62
|
now = int(time.time())
|
|
62
|
-
token = provider._encode_token(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
token = provider._encode_token(
|
|
64
|
+
{
|
|
65
|
+
"typ": "access",
|
|
66
|
+
"sub": "client-123",
|
|
67
|
+
"scopes": ["cited"],
|
|
68
|
+
"user_jwt": _make_jwt(-60), # expired backend JWT
|
|
69
|
+
"exp": now + 3600,
|
|
70
|
+
"iat": now,
|
|
71
|
+
}
|
|
72
|
+
)
|
|
70
73
|
|
|
71
74
|
result = run(provider.load_access_token(token))
|
|
72
75
|
assert result is None
|
|
@@ -75,14 +78,16 @@ class TestLoadAccessToken:
|
|
|
75
78
|
provider = _make_provider()
|
|
76
79
|
valid_jwt = _make_jwt(3600)
|
|
77
80
|
now = int(time.time())
|
|
78
|
-
token = provider._encode_token(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
token = provider._encode_token(
|
|
82
|
+
{
|
|
83
|
+
"typ": "access",
|
|
84
|
+
"sub": "client-123",
|
|
85
|
+
"scopes": ["cited"],
|
|
86
|
+
"user_jwt": valid_jwt,
|
|
87
|
+
"exp": now + 3600,
|
|
88
|
+
"iat": now,
|
|
89
|
+
}
|
|
90
|
+
)
|
|
86
91
|
|
|
87
92
|
result = run(provider.load_access_token(token))
|
|
88
93
|
assert result is not None
|
|
@@ -94,14 +99,16 @@ class TestLoadRefreshToken:
|
|
|
94
99
|
provider = _make_provider()
|
|
95
100
|
client = _make_client()
|
|
96
101
|
now = int(time.time())
|
|
97
|
-
token = provider._encode_token(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
token = provider._encode_token(
|
|
103
|
+
{
|
|
104
|
+
"typ": "refresh",
|
|
105
|
+
"sub": client.client_id,
|
|
106
|
+
"scopes": ["cited"],
|
|
107
|
+
"user_jwt": _make_jwt(-60), # expired backend JWT
|
|
108
|
+
"exp": now + 86400,
|
|
109
|
+
"iat": now,
|
|
110
|
+
}
|
|
111
|
+
)
|
|
105
112
|
|
|
106
113
|
result = run(provider.load_refresh_token(client, token))
|
|
107
114
|
assert result is None
|
|
@@ -111,14 +118,16 @@ class TestLoadRefreshToken:
|
|
|
111
118
|
client = _make_client()
|
|
112
119
|
valid_jwt = _make_jwt(3600)
|
|
113
120
|
now = int(time.time())
|
|
114
|
-
token = provider._encode_token(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
token = provider._encode_token(
|
|
122
|
+
{
|
|
123
|
+
"typ": "refresh",
|
|
124
|
+
"sub": client.client_id,
|
|
125
|
+
"scopes": ["cited"],
|
|
126
|
+
"user_jwt": valid_jwt,
|
|
127
|
+
"exp": now + 86400,
|
|
128
|
+
"iat": now,
|
|
129
|
+
}
|
|
130
|
+
)
|
|
122
131
|
|
|
123
132
|
result = run(provider.load_refresh_token(client, token))
|
|
124
133
|
assert result is not None
|
|
@@ -73,6 +73,79 @@ class TestIsToolAllowed:
|
|
|
73
73
|
def test_get_usage_stats_enterprise_allowed(self):
|
|
74
74
|
assert is_tool_allowed("get_usage_stats", "enterprise") is True
|
|
75
75
|
|
|
76
|
+
# ---- v0.4.0 / v0.5.0 write tools — Scale-gated.
|
|
77
|
+
# Tier misclassifications here translate to either revenue loss (giving
|
|
78
|
+
# Scale features away free) or angry-customer paging (gating something
|
|
79
|
+
# that should be free). Per-tool assertions catch both directions; the
|
|
80
|
+
# bulk count test only catches gross deletions.
|
|
81
|
+
|
|
82
|
+
# Profile competitors
|
|
83
|
+
def test_list_profile_competitors_base_allowed(self):
|
|
84
|
+
assert is_tool_allowed("list_profile_competitors", "free") is True
|
|
85
|
+
|
|
86
|
+
def test_set_profile_competitors_growth_blocked(self):
|
|
87
|
+
assert is_tool_allowed("set_profile_competitors", "growth") is False
|
|
88
|
+
|
|
89
|
+
def test_set_profile_competitors_scale_allowed(self):
|
|
90
|
+
assert is_tool_allowed("set_profile_competitors", "scale") is True
|
|
91
|
+
|
|
92
|
+
# Persona CRUD
|
|
93
|
+
def test_create_persona_growth_blocked(self):
|
|
94
|
+
assert is_tool_allowed("create_persona", "growth") is False
|
|
95
|
+
|
|
96
|
+
def test_create_persona_scale_allowed(self):
|
|
97
|
+
assert is_tool_allowed("create_persona", "scale") is True
|
|
98
|
+
|
|
99
|
+
def test_update_persona_growth_blocked(self):
|
|
100
|
+
assert is_tool_allowed("update_persona", "growth") is False
|
|
101
|
+
|
|
102
|
+
def test_update_persona_scale_allowed(self):
|
|
103
|
+
assert is_tool_allowed("update_persona", "scale") is True
|
|
104
|
+
|
|
105
|
+
def test_delete_persona_growth_blocked(self):
|
|
106
|
+
assert is_tool_allowed("delete_persona", "growth") is False
|
|
107
|
+
|
|
108
|
+
def test_delete_persona_scale_allowed(self):
|
|
109
|
+
assert is_tool_allowed("delete_persona", "scale") is True
|
|
110
|
+
|
|
111
|
+
# Product CRUD
|
|
112
|
+
def test_create_product_growth_blocked(self):
|
|
113
|
+
assert is_tool_allowed("create_product", "growth") is False
|
|
114
|
+
|
|
115
|
+
def test_create_product_scale_allowed(self):
|
|
116
|
+
assert is_tool_allowed("create_product", "scale") is True
|
|
117
|
+
|
|
118
|
+
def test_update_product_growth_blocked(self):
|
|
119
|
+
assert is_tool_allowed("update_product", "growth") is False
|
|
120
|
+
|
|
121
|
+
def test_update_product_scale_allowed(self):
|
|
122
|
+
assert is_tool_allowed("update_product", "scale") is True
|
|
123
|
+
|
|
124
|
+
def test_delete_product_growth_blocked(self):
|
|
125
|
+
assert is_tool_allowed("delete_product", "growth") is False
|
|
126
|
+
|
|
127
|
+
def test_delete_product_scale_allowed(self):
|
|
128
|
+
assert is_tool_allowed("delete_product", "scale") is True
|
|
129
|
+
|
|
130
|
+
# Buyer-intent CRUD (v0.5.0 added update + delete)
|
|
131
|
+
def test_create_buyer_intent_growth_blocked(self):
|
|
132
|
+
assert is_tool_allowed("create_buyer_intent", "growth") is False
|
|
133
|
+
|
|
134
|
+
def test_create_buyer_intent_scale_allowed(self):
|
|
135
|
+
assert is_tool_allowed("create_buyer_intent", "scale") is True
|
|
136
|
+
|
|
137
|
+
def test_update_buyer_intent_growth_blocked(self):
|
|
138
|
+
assert is_tool_allowed("update_buyer_intent", "growth") is False
|
|
139
|
+
|
|
140
|
+
def test_update_buyer_intent_scale_allowed(self):
|
|
141
|
+
assert is_tool_allowed("update_buyer_intent", "scale") is True
|
|
142
|
+
|
|
143
|
+
def test_delete_buyer_intent_growth_blocked(self):
|
|
144
|
+
assert is_tool_allowed("delete_buyer_intent", "growth") is False
|
|
145
|
+
|
|
146
|
+
def test_delete_buyer_intent_scale_allowed(self):
|
|
147
|
+
assert is_tool_allowed("delete_buyer_intent", "scale") is True
|
|
148
|
+
|
|
76
149
|
|
|
77
150
|
class TestRequiredTier:
|
|
78
151
|
def test_ungated_tool(self):
|