oodle-sdk 0.1.0__py3-none-any.whl
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.
- oodle_sdk/__init__.py +10 -0
- oodle_sdk/_core/__init__.py +2 -0
- oodle_sdk/_core/content.py +126 -0
- oodle_sdk/_core/jsonvalue.py +48 -0
- oodle_sdk/_core/semconv.py +280 -0
- oodle_sdk/mcp/__init__.py +46 -0
- oodle_sdk/mcp/_hooks/__init__.py +8 -0
- oodle_sdk/mcp/_hooks/common.py +451 -0
- oodle_sdk/mcp/_hooks/mcp_v1.py +646 -0
- oodle_sdk/mcp/_hooks/mcp_v2.py +436 -0
- oodle_sdk/mcp/config.py +189 -0
- oodle_sdk/mcp/core.py +1111 -0
- oodle_sdk/mcp/domain.py +134 -0
- oodle_sdk/mcp/feedback.py +530 -0
- oodle_sdk/mcp/instrumentor.py +228 -0
- oodle_sdk/mcp/intent.py +88 -0
- oodle_sdk/mcp/message.py +157 -0
- oodle_sdk/mcp/metrics.py +128 -0
- oodle_sdk/py.typed +0 -0
- oodle_sdk/semconv.py +16 -0
- oodle_sdk-0.1.0.dist-info/METADATA +297 -0
- oodle_sdk-0.1.0.dist-info/RECORD +26 -0
- oodle_sdk-0.1.0.dist-info/WHEEL +4 -0
- oodle_sdk-0.1.0.dist-info/entry_points.txt +2 -0
- oodle_sdk-0.1.0.dist-info/licenses/LICENSE +202 -0
- oodle_sdk-0.1.0.dist-info/licenses/NOTICE +4 -0
oodle_sdk/__init__.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Redaction, serialization and limits for captured content.
|
|
3
|
+
|
|
4
|
+
Content capture is on by default, so every captured value passes here
|
|
5
|
+
before it reaches a span. The rules are in ``spec/mcp/attributes.md``,
|
|
6
|
+
section 6. Both languages serialize the same way, so one fixture value
|
|
7
|
+
has one length in both.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
from collections.abc import Iterable
|
|
15
|
+
from typing import Any, Final
|
|
16
|
+
|
|
17
|
+
from oodle_sdk._core.jsonvalue import as_list, as_object, as_str
|
|
18
|
+
|
|
19
|
+
DEFAULT_MAX_CONTENT_CHARS: Final = 4000
|
|
20
|
+
STATUS_DESCRIPTION_CHARS: Final = 500
|
|
21
|
+
REDACTED: Final = "[REDACTED]"
|
|
22
|
+
|
|
23
|
+
# Normalized key suffixes that name a credential. A key matches when its
|
|
24
|
+
# normalized form equals or ends with one of them.
|
|
25
|
+
CREDENTIAL_KEY_SUFFIXES: Final = (
|
|
26
|
+
"password",
|
|
27
|
+
"passwd",
|
|
28
|
+
"pwd",
|
|
29
|
+
"secret",
|
|
30
|
+
"token",
|
|
31
|
+
"apikey",
|
|
32
|
+
"accesskey",
|
|
33
|
+
"secretkey",
|
|
34
|
+
"privatekey",
|
|
35
|
+
"authorization",
|
|
36
|
+
"cookie",
|
|
37
|
+
"credential",
|
|
38
|
+
"credentials",
|
|
39
|
+
"bearer",
|
|
40
|
+
)
|
|
41
|
+
_CREDENTIAL_VALUE = re.compile(r"^(Bearer|Basic) \S+")
|
|
42
|
+
_KEY_NOISE = re.compile(r"[-_ ]")
|
|
43
|
+
_BINARY_ITEM_TYPES: Final = frozenset({"image", "audio"})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def normalize_key(key: str) -> str:
|
|
47
|
+
"""Lowercase a key and remove the separators, so `api_key` and `apiKey` meet."""
|
|
48
|
+
return _KEY_NOISE.sub("", key.lower())
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Redactor:
|
|
52
|
+
"""Redacts credential-like keys and values and binary content."""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self, extra_keys: Iterable[str] = (), keep_keys: Iterable[str] = ()
|
|
56
|
+
) -> None:
|
|
57
|
+
self._suffixes: tuple[str, ...] = CREDENTIAL_KEY_SUFFIXES + tuple(
|
|
58
|
+
normalize_key(k) for k in extra_keys
|
|
59
|
+
)
|
|
60
|
+
# The ends-with rule on "token" also hits pagination keys that a
|
|
61
|
+
# person needs to debug a call. A kept key wins over the list.
|
|
62
|
+
self._keep = frozenset(normalize_key(k) for k in keep_keys)
|
|
63
|
+
|
|
64
|
+
def is_credential_key(self, key: str) -> bool:
|
|
65
|
+
norm = normalize_key(key)
|
|
66
|
+
if norm in self._keep:
|
|
67
|
+
return False
|
|
68
|
+
return any(norm == s or norm.endswith(s) for s in self._suffixes)
|
|
69
|
+
|
|
70
|
+
def redact(self, value: Any) -> Any:
|
|
71
|
+
"""Give a copy of the value with secrets and binary data replaced."""
|
|
72
|
+
obj = as_object(value)
|
|
73
|
+
if obj is not None:
|
|
74
|
+
out: dict[str, Any] = {}
|
|
75
|
+
for key, item in obj.items():
|
|
76
|
+
out[key] = (
|
|
77
|
+
REDACTED if self.is_credential_key(key) else self.redact(item)
|
|
78
|
+
)
|
|
79
|
+
self._omit_binary(obj, out)
|
|
80
|
+
return out
|
|
81
|
+
items = as_list(value)
|
|
82
|
+
if items is not None:
|
|
83
|
+
return [self.redact(item) for item in items]
|
|
84
|
+
if isinstance(value, str) and _CREDENTIAL_VALUE.match(value):
|
|
85
|
+
return REDACTED
|
|
86
|
+
return value
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def _omit_binary(original: dict[str, Any], out: dict[str, Any]) -> None:
|
|
90
|
+
# Encoded binary data is large and tells a reader nothing. The type
|
|
91
|
+
# and the MIME type stay, so the trace still shows what was sent.
|
|
92
|
+
data = as_str(original.get("data"))
|
|
93
|
+
if original.get("type") in _BINARY_ITEM_TYPES and data is not None:
|
|
94
|
+
out["data"] = f"[{len(data)} chars omitted]"
|
|
95
|
+
blob = as_str(original.get("blob"))
|
|
96
|
+
if blob is not None:
|
|
97
|
+
out["blob"] = f"[{len(blob)} chars omitted]"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def dumps(value: Any) -> str:
|
|
101
|
+
"""Serialize compactly, the way both languages do."""
|
|
102
|
+
return json.dumps(value, separators=(",", ":"), ensure_ascii=False, default=str)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def cut(text: str, limit: int) -> str:
|
|
106
|
+
"""Cut a string to the limit and mark the cut with the original length."""
|
|
107
|
+
if len(text) <= limit:
|
|
108
|
+
return text
|
|
109
|
+
return text[:limit] + f"... [cut from {len(text)} chars]"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def content_attribute(value: Any, redactor: Redactor, limit: int) -> str:
|
|
113
|
+
"""Redact, serialize and cut one content value for a span attribute."""
|
|
114
|
+
return cut(dumps(redactor.redact(value)), limit)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def first_text(content: Any) -> str:
|
|
118
|
+
"""The text of the first text item in a tools/call content list, or empty."""
|
|
119
|
+
items = as_list(content)
|
|
120
|
+
if items is None:
|
|
121
|
+
return ""
|
|
122
|
+
for item in items:
|
|
123
|
+
obj = as_object(item)
|
|
124
|
+
if obj is not None and obj.get("type") == "text":
|
|
125
|
+
return as_str(obj.get("text")) or ""
|
|
126
|
+
return ""
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Typed views of untyped JSON values.
|
|
3
|
+
|
|
4
|
+
A JSON-RPC message is ``Any`` all the way down. These helpers give each
|
|
5
|
+
read a type, so the type checkers can check the code that uses the value.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Mapping, Sequence
|
|
11
|
+
from typing import Any, cast
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def as_object(value: Any) -> dict[str, Any] | None:
|
|
15
|
+
"""The value as a JSON object (a copy), or None when it is not one."""
|
|
16
|
+
if value is None:
|
|
17
|
+
return None
|
|
18
|
+
if type(value) is dict:
|
|
19
|
+
# The common case, on every message: a copy without a Python loop.
|
|
20
|
+
# The ABC check below costs more than the copy.
|
|
21
|
+
return dict(cast("dict[str, Any]", value))
|
|
22
|
+
if isinstance(value, Mapping):
|
|
23
|
+
items = cast("Mapping[Any, Any]", value)
|
|
24
|
+
return {str(k): v for k, v in items.items()}
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_object(value: Any) -> bool:
|
|
29
|
+
"""True for a JSON object. The dict check first: the ABC check is slow."""
|
|
30
|
+
return type(value) is dict or isinstance(value, Mapping)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def as_list(value: Any) -> list[Any] | None:
|
|
34
|
+
"""The value as a JSON array, or None when it is not one."""
|
|
35
|
+
if isinstance(value, list):
|
|
36
|
+
return list(cast("list[Any]", value))
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def as_sequence(value: Any) -> list[Any] | None:
|
|
41
|
+
"""The value as a list, also from a tuple, or None."""
|
|
42
|
+
if isinstance(value, (list, tuple)):
|
|
43
|
+
return list(cast("Sequence[Any]", value))
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def as_str(value: Any) -> str | None:
|
|
48
|
+
return value if isinstance(value, str) else None
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Attribute, metric and event names that the MCP module records.
|
|
3
|
+
|
|
4
|
+
A name comes from the OpenTelemetry semantic conventions when one
|
|
5
|
+
exists. A name in the PROPOSED set has no convention yet; the draft
|
|
6
|
+
proposal is in ``spec/upstream/semconv-proposal.md``. Every proposed
|
|
7
|
+
name lives in this module and nowhere else, so a rename upstream is one
|
|
8
|
+
change. The contract is ``spec/mcp/attributes.md``.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Final
|
|
14
|
+
|
|
15
|
+
# --- semconv: general ------------------------------------------------------
|
|
16
|
+
ERROR_TYPE: Final = "error.type"
|
|
17
|
+
CLIENT_ADDRESS: Final = "client.address"
|
|
18
|
+
SERVER_ADDRESS: Final = "server.address"
|
|
19
|
+
SERVER_PORT: Final = "server.port"
|
|
20
|
+
USER_AGENT_ORIGINAL: Final = "user_agent.original"
|
|
21
|
+
NETWORK_TRANSPORT: Final = "network.transport"
|
|
22
|
+
NETWORK_PROTOCOL_NAME: Final = "network.protocol.name"
|
|
23
|
+
NETWORK_PROTOCOL_VERSION: Final = "network.protocol.version"
|
|
24
|
+
RPC_STATUS_CODE: Final = "rpc.status_code"
|
|
25
|
+
JSONRPC_REQUEST_ID: Final = "jsonrpc.request.id"
|
|
26
|
+
|
|
27
|
+
# --- semconv: gen_ai -------------------------------------------------------
|
|
28
|
+
GEN_AI_OPERATION_NAME: Final = "gen_ai.operation.name"
|
|
29
|
+
GEN_AI_TOOL_NAME: Final = "gen_ai.tool.name"
|
|
30
|
+
GEN_AI_PROMPT_NAME: Final = "gen_ai.prompt.name"
|
|
31
|
+
GEN_AI_TOOL_CALL_ARGUMENTS: Final = "gen_ai.tool.call.arguments"
|
|
32
|
+
GEN_AI_TOOL_CALL_RESULT: Final = "gen_ai.tool.call.result"
|
|
33
|
+
GEN_AI_PROMPT_VARIABLES: Final = "gen_ai.prompt.variables"
|
|
34
|
+
OPERATION_EXECUTE_TOOL: Final = "execute_tool"
|
|
35
|
+
|
|
36
|
+
# --- semconv: mcp ----------------------------------------------------------
|
|
37
|
+
MCP_METHOD_NAME: Final = "mcp.method.name"
|
|
38
|
+
MCP_PROTOCOL_VERSION: Final = "mcp.protocol.version"
|
|
39
|
+
MCP_SESSION_ID: Final = "mcp.session.id"
|
|
40
|
+
MCP_RESOURCE_URI: Final = "mcp.resource.uri"
|
|
41
|
+
MCP_CLIENT_NAME: Final = "mcp.client.name"
|
|
42
|
+
MCP_CLIENT_VERSION: Final = "mcp.client.version"
|
|
43
|
+
|
|
44
|
+
METRIC_SERVER_OPERATION_DURATION: Final = "mcp.server.operation.duration"
|
|
45
|
+
METRIC_CLIENT_OPERATION_DURATION: Final = "mcp.client.operation.duration"
|
|
46
|
+
METRIC_SERVER_SESSION_DURATION: Final = "mcp.server.session.duration"
|
|
47
|
+
METRIC_CLIENT_SESSION_DURATION: Final = "mcp.client.session.duration"
|
|
48
|
+
|
|
49
|
+
# The advisory bucket boundaries of the conventions, in seconds.
|
|
50
|
+
DURATION_BUCKETS: Final = (
|
|
51
|
+
0.01,
|
|
52
|
+
0.025,
|
|
53
|
+
0.05,
|
|
54
|
+
0.1,
|
|
55
|
+
0.25,
|
|
56
|
+
0.5,
|
|
57
|
+
1.0,
|
|
58
|
+
2.5,
|
|
59
|
+
5.0,
|
|
60
|
+
10.0,
|
|
61
|
+
30.0,
|
|
62
|
+
60.0,
|
|
63
|
+
120.0,
|
|
64
|
+
300.0,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# --- proposed (no convention yet) -----------------------------------------
|
|
68
|
+
GEN_AI_TOOL_CALL_INTENT: Final = "gen_ai.tool.call.intent"
|
|
69
|
+
GEN_AI_FEEDBACK_ID: Final = "gen_ai.feedback.id"
|
|
70
|
+
GEN_AI_FEEDBACK_TYPE: Final = "gen_ai.feedback.type"
|
|
71
|
+
GEN_AI_FEEDBACK_CATEGORY: Final = "gen_ai.feedback.category"
|
|
72
|
+
GEN_AI_FEEDBACK_SEVERITY: Final = "gen_ai.feedback.severity"
|
|
73
|
+
GEN_AI_FEEDBACK_SUMMARY: Final = "gen_ai.feedback.summary"
|
|
74
|
+
GEN_AI_FEEDBACK_ACTUAL: Final = "gen_ai.feedback.actual"
|
|
75
|
+
GEN_AI_FEEDBACK_EXPECTED: Final = "gen_ai.feedback.expected"
|
|
76
|
+
GEN_AI_FEEDBACK_WORKAROUND: Final = "gen_ai.feedback.workaround"
|
|
77
|
+
GEN_AI_FEEDBACK_PROPOSAL: Final = "gen_ai.feedback.proposal"
|
|
78
|
+
GEN_AI_FEEDBACK_MODEL: Final = "gen_ai.feedback.model"
|
|
79
|
+
GEN_AI_FEEDBACK_TOOL_NAME: Final = "gen_ai.feedback.tool.name"
|
|
80
|
+
GEN_AI_FEEDBACK_TOOL_CALL_ARGUMENTS: Final = "gen_ai.feedback.tool.call.arguments"
|
|
81
|
+
EVENT_GEN_AI_FEEDBACK: Final = "gen_ai.feedback"
|
|
82
|
+
METRIC_GEN_AI_FEEDBACK_REPORTS: Final = "gen_ai.feedback.reports"
|
|
83
|
+
MCP_RESOURCE_CONTENTS: Final = "mcp.resource.contents"
|
|
84
|
+
|
|
85
|
+
FEEDBACK_TYPE_BUG: Final = "bug"
|
|
86
|
+
FEEDBACK_TYPE_FEATURE_REQUEST: Final = "feature_request"
|
|
87
|
+
|
|
88
|
+
PROPOSED: Final = frozenset(
|
|
89
|
+
{
|
|
90
|
+
GEN_AI_TOOL_CALL_INTENT,
|
|
91
|
+
GEN_AI_FEEDBACK_ID,
|
|
92
|
+
GEN_AI_FEEDBACK_TYPE,
|
|
93
|
+
GEN_AI_FEEDBACK_CATEGORY,
|
|
94
|
+
GEN_AI_FEEDBACK_SEVERITY,
|
|
95
|
+
GEN_AI_FEEDBACK_SUMMARY,
|
|
96
|
+
GEN_AI_FEEDBACK_ACTUAL,
|
|
97
|
+
GEN_AI_FEEDBACK_EXPECTED,
|
|
98
|
+
GEN_AI_FEEDBACK_WORKAROUND,
|
|
99
|
+
GEN_AI_FEEDBACK_PROPOSAL,
|
|
100
|
+
GEN_AI_FEEDBACK_MODEL,
|
|
101
|
+
GEN_AI_FEEDBACK_TOOL_NAME,
|
|
102
|
+
GEN_AI_FEEDBACK_TOOL_CALL_ARGUMENTS,
|
|
103
|
+
EVENT_GEN_AI_FEEDBACK,
|
|
104
|
+
METRIC_GEN_AI_FEEDBACK_REPORTS,
|
|
105
|
+
MCP_RESOURCE_CONTENTS,
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
# The proposed names that are signals, not span attributes.
|
|
109
|
+
PROPOSED_SIGNALS: Final = frozenset(
|
|
110
|
+
{EVENT_GEN_AI_FEEDBACK, METRIC_GEN_AI_FEEDBACK_REPORTS}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Every span attribute the SDK itself sets. A domain attribute with one of
|
|
114
|
+
# these keys is ignored, because a host value there would break the
|
|
115
|
+
# queries that read the convention name.
|
|
116
|
+
SDK_SPAN_ATTRIBUTES: Final = frozenset(
|
|
117
|
+
{
|
|
118
|
+
ERROR_TYPE,
|
|
119
|
+
CLIENT_ADDRESS,
|
|
120
|
+
SERVER_ADDRESS,
|
|
121
|
+
SERVER_PORT,
|
|
122
|
+
USER_AGENT_ORIGINAL,
|
|
123
|
+
NETWORK_TRANSPORT,
|
|
124
|
+
NETWORK_PROTOCOL_NAME,
|
|
125
|
+
NETWORK_PROTOCOL_VERSION,
|
|
126
|
+
RPC_STATUS_CODE,
|
|
127
|
+
JSONRPC_REQUEST_ID,
|
|
128
|
+
GEN_AI_OPERATION_NAME,
|
|
129
|
+
GEN_AI_TOOL_NAME,
|
|
130
|
+
GEN_AI_PROMPT_NAME,
|
|
131
|
+
GEN_AI_TOOL_CALL_ARGUMENTS,
|
|
132
|
+
GEN_AI_TOOL_CALL_RESULT,
|
|
133
|
+
GEN_AI_PROMPT_VARIABLES,
|
|
134
|
+
MCP_METHOD_NAME,
|
|
135
|
+
MCP_PROTOCOL_VERSION,
|
|
136
|
+
MCP_SESSION_ID,
|
|
137
|
+
MCP_RESOURCE_URI,
|
|
138
|
+
MCP_CLIENT_NAME,
|
|
139
|
+
MCP_CLIENT_VERSION,
|
|
140
|
+
}
|
|
141
|
+
| (PROPOSED - PROPOSED_SIGNALS)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# --- values ----------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
# The fallback the conventions define for error.type. The SDK uses the same
|
|
147
|
+
# token for every guarded metric attribute, so one query finds them all.
|
|
148
|
+
OTHER: Final = "_OTHER"
|
|
149
|
+
TOOL_ERROR: Final = "tool_error"
|
|
150
|
+
|
|
151
|
+
# JSON-RPC codes that say the caller sent a request the server could not
|
|
152
|
+
# serve. They are not server failures and keep the span status UNSET.
|
|
153
|
+
NOT_SERVER_ERROR_CODES: Final = frozenset({-32700, -32600, -32601, -32602, -32002})
|
|
154
|
+
|
|
155
|
+
# The well-known values of mcp.method.name. Any other method is _OTHER in
|
|
156
|
+
# metrics, because a client can send any text there.
|
|
157
|
+
METHOD_INITIALIZE: Final = "initialize"
|
|
158
|
+
METHOD_TOOLS_LIST: Final = "tools/list"
|
|
159
|
+
METHOD_TOOLS_CALL: Final = "tools/call"
|
|
160
|
+
METHOD_PROMPTS_LIST: Final = "prompts/list"
|
|
161
|
+
METHOD_PROMPTS_GET: Final = "prompts/get"
|
|
162
|
+
METHOD_RESOURCES_READ: Final = "resources/read"
|
|
163
|
+
METHOD_CANCELLED: Final = "notifications/cancelled"
|
|
164
|
+
KNOWN_METHODS: Final = frozenset(
|
|
165
|
+
{
|
|
166
|
+
"completion/complete",
|
|
167
|
+
"elicitation/create",
|
|
168
|
+
"initialize",
|
|
169
|
+
"logging/setLevel",
|
|
170
|
+
"notifications/cancelled",
|
|
171
|
+
"notifications/initialized",
|
|
172
|
+
"notifications/message",
|
|
173
|
+
"notifications/progress",
|
|
174
|
+
"notifications/prompts/list_changed",
|
|
175
|
+
"notifications/resources/list_changed",
|
|
176
|
+
"notifications/resources/updated",
|
|
177
|
+
"notifications/roots/list_changed",
|
|
178
|
+
"notifications/tools/list_changed",
|
|
179
|
+
"ping",
|
|
180
|
+
"prompts/get",
|
|
181
|
+
"prompts/list",
|
|
182
|
+
"resources/list",
|
|
183
|
+
"resources/read",
|
|
184
|
+
"resources/subscribe",
|
|
185
|
+
"resources/templates/list",
|
|
186
|
+
"resources/unsubscribe",
|
|
187
|
+
"roots/list",
|
|
188
|
+
"sampling/createMessage",
|
|
189
|
+
"tools/call",
|
|
190
|
+
"tools/list",
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
RESOURCE_URI_METHODS: Final = frozenset(
|
|
194
|
+
{
|
|
195
|
+
"resources/read",
|
|
196
|
+
"resources/subscribe",
|
|
197
|
+
"resources/unsubscribe",
|
|
198
|
+
"notifications/resources/updated",
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Keys that the 2026-07-28 MCP revision puts in params._meta of every
|
|
203
|
+
# request. Older clients send this information once, in initialize.
|
|
204
|
+
META_PROTOCOL_VERSION: Final = "io.modelcontextprotocol/protocolVersion"
|
|
205
|
+
META_CLIENT_INFO: Final = "io.modelcontextprotocol/clientInfo"
|
|
206
|
+
|
|
207
|
+
TRANSPORT_TCP: Final = "tcp"
|
|
208
|
+
TRANSPORT_PIPE: Final = "pipe"
|
|
209
|
+
PROTOCOL_HTTP: Final = "http"
|
|
210
|
+
|
|
211
|
+
# Every name above: ``oodle_sdk.semconv`` re-exports this list, and a test
|
|
212
|
+
# checks that no name is missing from it.
|
|
213
|
+
__all__ = [
|
|
214
|
+
"CLIENT_ADDRESS",
|
|
215
|
+
"DURATION_BUCKETS",
|
|
216
|
+
"ERROR_TYPE",
|
|
217
|
+
"EVENT_GEN_AI_FEEDBACK",
|
|
218
|
+
"FEEDBACK_TYPE_BUG",
|
|
219
|
+
"FEEDBACK_TYPE_FEATURE_REQUEST",
|
|
220
|
+
"GEN_AI_FEEDBACK_ACTUAL",
|
|
221
|
+
"GEN_AI_FEEDBACK_CATEGORY",
|
|
222
|
+
"GEN_AI_FEEDBACK_EXPECTED",
|
|
223
|
+
"GEN_AI_FEEDBACK_ID",
|
|
224
|
+
"GEN_AI_FEEDBACK_MODEL",
|
|
225
|
+
"GEN_AI_FEEDBACK_PROPOSAL",
|
|
226
|
+
"GEN_AI_FEEDBACK_SEVERITY",
|
|
227
|
+
"GEN_AI_FEEDBACK_SUMMARY",
|
|
228
|
+
"GEN_AI_FEEDBACK_TOOL_CALL_ARGUMENTS",
|
|
229
|
+
"GEN_AI_FEEDBACK_TOOL_NAME",
|
|
230
|
+
"GEN_AI_FEEDBACK_TYPE",
|
|
231
|
+
"GEN_AI_FEEDBACK_WORKAROUND",
|
|
232
|
+
"GEN_AI_OPERATION_NAME",
|
|
233
|
+
"GEN_AI_PROMPT_NAME",
|
|
234
|
+
"GEN_AI_PROMPT_VARIABLES",
|
|
235
|
+
"GEN_AI_TOOL_CALL_ARGUMENTS",
|
|
236
|
+
"GEN_AI_TOOL_CALL_INTENT",
|
|
237
|
+
"GEN_AI_TOOL_CALL_RESULT",
|
|
238
|
+
"GEN_AI_TOOL_NAME",
|
|
239
|
+
"JSONRPC_REQUEST_ID",
|
|
240
|
+
"KNOWN_METHODS",
|
|
241
|
+
"MCP_CLIENT_NAME",
|
|
242
|
+
"MCP_CLIENT_VERSION",
|
|
243
|
+
"MCP_METHOD_NAME",
|
|
244
|
+
"MCP_PROTOCOL_VERSION",
|
|
245
|
+
"MCP_RESOURCE_CONTENTS",
|
|
246
|
+
"MCP_RESOURCE_URI",
|
|
247
|
+
"MCP_SESSION_ID",
|
|
248
|
+
"META_CLIENT_INFO",
|
|
249
|
+
"META_PROTOCOL_VERSION",
|
|
250
|
+
"METHOD_CANCELLED",
|
|
251
|
+
"METHOD_INITIALIZE",
|
|
252
|
+
"METHOD_PROMPTS_GET",
|
|
253
|
+
"METHOD_PROMPTS_LIST",
|
|
254
|
+
"METHOD_RESOURCES_READ",
|
|
255
|
+
"METHOD_TOOLS_CALL",
|
|
256
|
+
"METHOD_TOOLS_LIST",
|
|
257
|
+
"METRIC_CLIENT_OPERATION_DURATION",
|
|
258
|
+
"METRIC_CLIENT_SESSION_DURATION",
|
|
259
|
+
"METRIC_GEN_AI_FEEDBACK_REPORTS",
|
|
260
|
+
"METRIC_SERVER_OPERATION_DURATION",
|
|
261
|
+
"METRIC_SERVER_SESSION_DURATION",
|
|
262
|
+
"NETWORK_PROTOCOL_NAME",
|
|
263
|
+
"NETWORK_PROTOCOL_VERSION",
|
|
264
|
+
"NETWORK_TRANSPORT",
|
|
265
|
+
"NOT_SERVER_ERROR_CODES",
|
|
266
|
+
"OPERATION_EXECUTE_TOOL",
|
|
267
|
+
"OTHER",
|
|
268
|
+
"PROPOSED",
|
|
269
|
+
"PROPOSED_SIGNALS",
|
|
270
|
+
"PROTOCOL_HTTP",
|
|
271
|
+
"RESOURCE_URI_METHODS",
|
|
272
|
+
"RPC_STATUS_CODE",
|
|
273
|
+
"SDK_SPAN_ATTRIBUTES",
|
|
274
|
+
"SERVER_ADDRESS",
|
|
275
|
+
"SERVER_PORT",
|
|
276
|
+
"TOOL_ERROR",
|
|
277
|
+
"TRANSPORT_PIPE",
|
|
278
|
+
"TRANSPORT_TCP",
|
|
279
|
+
"USER_AGENT_ORIGINAL",
|
|
280
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""MCP observability: traces, metrics, agent intent and agent feedback.
|
|
3
|
+
|
|
4
|
+
``instrument(server)`` traces one server, ``instrument_client(session)`` one
|
|
5
|
+
client, and ``McpInstrumentor`` every server and client of the process. The
|
|
6
|
+
pure core (``ServerCore``, ``ClientCore``) is what the library hooks feed.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from oodle_sdk.mcp.config import FeedbackConfig, IntentConfig, McpConfig
|
|
10
|
+
from oodle_sdk.mcp.core import (
|
|
11
|
+
ClientCore,
|
|
12
|
+
InboundMessage,
|
|
13
|
+
OutboundMessage,
|
|
14
|
+
ServerCore,
|
|
15
|
+
ServerRegistry,
|
|
16
|
+
ToolRun,
|
|
17
|
+
)
|
|
18
|
+
from oodle_sdk.mcp.feedback import FeedbackReport
|
|
19
|
+
from oodle_sdk.mcp.instrumentor import (
|
|
20
|
+
McpInstrumentor,
|
|
21
|
+
instrument,
|
|
22
|
+
instrument_client,
|
|
23
|
+
uninstrument,
|
|
24
|
+
)
|
|
25
|
+
from oodle_sdk.mcp.message import HttpInfo, ProviderRequest, SessionState, TransportInfo
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"ClientCore",
|
|
29
|
+
"FeedbackConfig",
|
|
30
|
+
"FeedbackReport",
|
|
31
|
+
"HttpInfo",
|
|
32
|
+
"InboundMessage",
|
|
33
|
+
"IntentConfig",
|
|
34
|
+
"McpConfig",
|
|
35
|
+
"McpInstrumentor",
|
|
36
|
+
"OutboundMessage",
|
|
37
|
+
"ProviderRequest",
|
|
38
|
+
"ServerCore",
|
|
39
|
+
"ServerRegistry",
|
|
40
|
+
"SessionState",
|
|
41
|
+
"ToolRun",
|
|
42
|
+
"TransportInfo",
|
|
43
|
+
"instrument",
|
|
44
|
+
"instrument_client",
|
|
45
|
+
"uninstrument",
|
|
46
|
+
]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Adapters between the MCP libraries and the pure core.
|
|
3
|
+
|
|
4
|
+
Each module here knows one library generation. It turns the library's
|
|
5
|
+
request objects into JSON-RPC dicts for ``ServerCore.receive`` and
|
|
6
|
+
``ClientCore.send``, and puts the core's answer back into the library's
|
|
7
|
+
types. Nothing in this package records a span or a metric itself.
|
|
8
|
+
"""
|