oodle-sdk 0.1.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.
- oodle_sdk-0.1.0/.gitignore +24 -0
- oodle_sdk-0.1.0/LICENSE +202 -0
- oodle_sdk-0.1.0/NOTICE +4 -0
- oodle_sdk-0.1.0/PKG-INFO +297 -0
- oodle_sdk-0.1.0/README.md +266 -0
- oodle_sdk-0.1.0/pyproject.toml +112 -0
- oodle_sdk-0.1.0/src/oodle_sdk/__init__.py +10 -0
- oodle_sdk-0.1.0/src/oodle_sdk/_core/__init__.py +2 -0
- oodle_sdk-0.1.0/src/oodle_sdk/_core/content.py +126 -0
- oodle_sdk-0.1.0/src/oodle_sdk/_core/jsonvalue.py +48 -0
- oodle_sdk-0.1.0/src/oodle_sdk/_core/semconv.py +280 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/__init__.py +46 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/_hooks/__init__.py +8 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/_hooks/common.py +451 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/_hooks/mcp_v1.py +646 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/_hooks/mcp_v2.py +436 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/config.py +189 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/core.py +1111 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/domain.py +134 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/feedback.py +530 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/instrumentor.py +228 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/intent.py +88 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/message.py +157 -0
- oodle_sdk-0.1.0/src/oodle_sdk/mcp/metrics.py +128 -0
- oodle_sdk-0.1.0/src/oodle_sdk/py.typed +0 -0
- oodle_sdk-0.1.0/src/oodle_sdk/semconv.py +16 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
.venv/
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
.mypy_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
|
|
12
|
+
# Node
|
|
13
|
+
node_modules/
|
|
14
|
+
coverage/
|
|
15
|
+
*.tsbuildinfo
|
|
16
|
+
|
|
17
|
+
# Editors and OS
|
|
18
|
+
.DS_Store
|
|
19
|
+
.idea/
|
|
20
|
+
.vscode/
|
|
21
|
+
*.swp
|
|
22
|
+
|
|
23
|
+
# Cross-language e2e
|
|
24
|
+
e2e/cross-language/.venv/
|
oodle_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
oodle_sdk-0.1.0/NOTICE
ADDED
oodle_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: oodle-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenTelemetry instrumentation for MCP servers and clients, with agent intent and feedback
|
|
5
|
+
Project-URL: Homepage, https://github.com/oodle-ai/oodle-sdk
|
|
6
|
+
Project-URL: Documentation, https://docs.oodle.ai
|
|
7
|
+
Project-URL: Source, https://github.com/oodle-ai/oodle-sdk
|
|
8
|
+
Project-URL: Changelog, https://github.com/oodle-ai/oodle-sdk/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Oodle AI <support@oodle.ai>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: agents,mcp,observability,opentelemetry,tracing
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: opentelemetry-api>=1.26
|
|
25
|
+
Requires-Dist: opentelemetry-instrumentation>=0.47b0
|
|
26
|
+
Provides-Extra: fastmcp
|
|
27
|
+
Requires-Dist: fastmcp>=2.0; extra == 'fastmcp'
|
|
28
|
+
Provides-Extra: mcp
|
|
29
|
+
Requires-Dist: mcp>=1.21.1; extra == 'mcp'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# oodle-sdk (Python)
|
|
33
|
+
|
|
34
|
+
OpenTelemetry instrumentation for [Model Context Protocol](https://modelcontextprotocol.io)
|
|
35
|
+
servers and clients, with agent intent and agent feedback. Part of the
|
|
36
|
+
[Oodle SDK](https://github.com/oodle-ai/oodle-sdk); the TypeScript package
|
|
37
|
+
is [`@oodle-ai/sdk`](https://www.npmjs.com/package/@oodle-ai/sdk).
|
|
38
|
+
|
|
39
|
+
- One `SERVER` span per request and one `CLIENT` span per call, named and
|
|
40
|
+
labeled by the
|
|
41
|
+
[OpenTelemetry GenAI conventions for MCP](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/mcp.md),
|
|
42
|
+
and the `mcp.*.operation.duration` and `mcp.*.session.duration` metrics.
|
|
43
|
+
- Trace context from the client to the server in `params._meta`: an agent's
|
|
44
|
+
prompt and every tool call it makes are one trace, also over stdio.
|
|
45
|
+
- An optional `intent` argument on each tool (`gen_ai.tool.call.intent`) and
|
|
46
|
+
the `report_bug` and `request_feature` tools (`gen_ai.feedback.*`).
|
|
47
|
+
- Works with `mcp` 1.21.1 and later, `mcp` 2.x, and standalone `fastmcp` 2.x
|
|
48
|
+
and 4.x, on Python 3.10 to 3.13. Runtime dependencies: `opentelemetry-api`
|
|
49
|
+
and `opentelemetry-instrumentation` only; the MCP library is an extra.
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "oodle-sdk[mcp]" # or "oodle-sdk[fastmcp]", or oodle-sdk next to the mcp you have
|
|
55
|
+
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http # export
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from mcp.server.mcpserver import MCPServer
|
|
62
|
+
from opentelemetry import metrics, trace
|
|
63
|
+
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
|
|
64
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
|
65
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
66
|
+
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
|
|
67
|
+
from opentelemetry.sdk.resources import Resource
|
|
68
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
69
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
70
|
+
|
|
71
|
+
from oodle_sdk.mcp import FeedbackConfig, instrument
|
|
72
|
+
|
|
73
|
+
# Standard OpenTelemetry setup: the SDK uses the global providers.
|
|
74
|
+
resource = Resource.create({"service.name": "weather-mcp"})
|
|
75
|
+
tracer_provider = TracerProvider(resource=resource)
|
|
76
|
+
tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
|
|
77
|
+
trace.set_tracer_provider(tracer_provider)
|
|
78
|
+
metrics.set_meter_provider(
|
|
79
|
+
MeterProvider(
|
|
80
|
+
resource=resource,
|
|
81
|
+
metric_readers=[PeriodicExportingMetricReader(OTLPMetricExporter())],
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
mcp = MCPServer("weather")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@mcp.tool()
|
|
89
|
+
def forecast(city: str) -> str:
|
|
90
|
+
"""The forecast for one city."""
|
|
91
|
+
return f"Sunny in {city}"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# One line: spans, metrics, the intent argument and the feedback tools.
|
|
95
|
+
instrument(mcp, feedback=FeedbackConfig(team="the weather team"))
|
|
96
|
+
mcp.run()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT="https://<your OTLP endpoint>"
|
|
101
|
+
export OTEL_EXPORTER_OTLP_HEADERS="<the headers your backend needs>"
|
|
102
|
+
python server.py
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The snippet is for `mcp` 2.x, which a fresh install resolves. On `mcp` 1.x
|
|
106
|
+
the server is `FastMCP` from `mcp.server.fastmcp`; the rest is the same.
|
|
107
|
+
|
|
108
|
+
`instrument(server, config=None, *, tracer_provider=None, meter_provider=None,
|
|
109
|
+
**options)` takes an `mcp` 2.x `MCPServer`, an `mcp` 1.x `FastMCP` or
|
|
110
|
+
low-level `Server`, or a standalone `fastmcp` server. The options are the fields of
|
|
111
|
+
`McpConfig`, as keyword arguments or as one `McpConfig`. Without providers
|
|
112
|
+
it uses the global ones. It returns the core; `core.tool_span(name, args)`
|
|
113
|
+
opens an `execute_tool {name}` span for a host that runs tools behind a
|
|
114
|
+
wrapper tool.
|
|
115
|
+
|
|
116
|
+
A client session: `instrument_client(session, server_url="http://host/mcp")`.
|
|
117
|
+
When the session is built through `streamablehttp_client`, the SDK learns the
|
|
118
|
+
URL itself. `uninstrument()` removes every patch.
|
|
119
|
+
|
|
120
|
+
## Zero-code: `opentelemetry-instrument`
|
|
121
|
+
|
|
122
|
+
The package registers the instrumentor under the entry point `oodle_mcp`, so
|
|
123
|
+
`opentelemetry-instrument` traces every server and client in the process
|
|
124
|
+
without a code change:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install "oodle-sdk[mcp]" opentelemetry-distro opentelemetry-exporter-otlp-proto-http
|
|
128
|
+
OTEL_SERVICE_NAME=weather-mcp OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
|
|
129
|
+
opentelemetry-instrument python server.py
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=oodle_mcp` turns it off. In code,
|
|
133
|
+
`McpInstrumentor().instrument(tracer_provider=..., meter_provider=...,
|
|
134
|
+
config=McpConfig(...))` does the same. A server that is also instrumented
|
|
135
|
+
by hand gets one set of spans, not two.
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
Code options win over environment variables, which win over defaults, with
|
|
140
|
+
one exception: `OODLE_MCP_INTENT=false` and `OODLE_MCP_FEEDBACK=false` turn
|
|
141
|
+
the feature off also when code turned it on, so an operator can quiet a
|
|
142
|
+
deployment. No environment variable turns a feature on.
|
|
143
|
+
|
|
144
|
+
| Option | Default | Environment | Meaning |
|
|
145
|
+
| --- | --- | --- | --- |
|
|
146
|
+
| `capture_content` | `True` | `OODLE_MCP_CAPTURE_CONTENT`, `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` | Record tool arguments, tool results, prompt variables and resource contents on spans. The environment can only turn it off. |
|
|
147
|
+
| `max_content_chars` | `4000` | `OODLE_MCP_MAX_CONTENT_CHARS` | Code points kept per content attribute; a longer value ends with `... [cut from N chars]`. |
|
|
148
|
+
| `redact_keys` | `()` | | Keys whose values become `[REDACTED]`, added to the built-in list (`password`, `secret`, `token`, `apikey`, `authorization`, `cookie`, ...). |
|
|
149
|
+
| `keep_keys` | `()` | | Keys the built-in list must leave as they are (`next_token`, `page_token`). |
|
|
150
|
+
| `trace_notifications` | `False` | | Also open a span for each JSON-RPC notification. |
|
|
151
|
+
| `augment_instructions` | `True` | | Add a short text to the server instructions that asks the agent to send an intent and to report problems. |
|
|
152
|
+
| `intent` | `True` | `OODLE_MCP_INTENT` | The intent argument. `IntentConfig(property="intent", description=..., exclude_tools=frozenset(), recover_from_json_args=())` for the details. The environment can only turn it off, also against code. |
|
|
153
|
+
| `feedback` | `True` | `OODLE_MCP_FEEDBACK` | The feedback tools. `FeedbackConfig(report_bug="report_bug", request_feature="request_feature", team=..., report_bug_description=None, request_feature_description=None, empty_report_message=None, bug_hint=True, log_reports=True, on_feedback=None, should_hint=None)` for the details; `report_bug=None` turns one tool off, a `*_description` replaces the tool's description, `empty_report_message` replaces the reply to a bug report that names no tool and no problem (`{tool}` takes the report_bug name). The environment can only turn it off, also against code. |
|
|
154
|
+
| `attributes` | `{}` | | Domain attributes added to every span the SDK opens: values that do not change in a process (deployment, region). |
|
|
155
|
+
| `attributes_provider` | `None` | | `provider(request: ProviderRequest) -> Mapping`, called once per MCP message before the span starts, in that message's context. `request` gives `method`, `tool_name`, `prompt_name`, `params` (intent removed), `meta`, `client_name`, `client_version`, `session_id` and `headers`. An exception or a bad value never fails the call. |
|
|
156
|
+
| `baggage_attributes` | `()` | | Baggage keys copied from the incoming context onto the span. |
|
|
157
|
+
| `metric_attributes` | `()` | | The domain keys that also go on the duration and feedback metrics. Empty by default: each value is a new series. |
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
instrument(
|
|
161
|
+
mcp,
|
|
162
|
+
attributes={"deployment.environment.name": "production"},
|
|
163
|
+
attributes_provider=lambda request: {
|
|
164
|
+
"example.tenant": request.headers.get("x-tenant", "unknown"),
|
|
165
|
+
},
|
|
166
|
+
metric_attributes=["example.tenant"],
|
|
167
|
+
feedback=FeedbackConfig(team="the weather team", on_feedback=store_report),
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
A domain key never replaces an attribute the SDK set. Domain attributes go
|
|
172
|
+
on the server and client spans, the `execute_tool` helper span, the feedback
|
|
173
|
+
span and event, and reach `on_feedback(report)` as `report.attributes`.
|
|
174
|
+
|
|
175
|
+
## Hosts that run tools behind a wrapper
|
|
176
|
+
|
|
177
|
+
A host whose agent reaches the real tools through one wrapper tool (a
|
|
178
|
+
`call_tool` dispatcher, a code runner) gets one request span named after the
|
|
179
|
+
wrapper. The core the `instrument` call returns gives it the rest:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from typing import Any
|
|
183
|
+
|
|
184
|
+
# On mcp 1.x: from mcp.server.fastmcp.exceptions import ToolError
|
|
185
|
+
from mcp.server.mcpserver.exceptions import ToolError
|
|
186
|
+
from mcp.types import TextContent
|
|
187
|
+
|
|
188
|
+
core = instrument(mcp, feedback=FeedbackConfig(team="the weather team"))
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
@mcp.tool()
|
|
192
|
+
def call_tool(tool: str, args: dict) -> Any:
|
|
193
|
+
# An intent the agent put inside the nested arguments.
|
|
194
|
+
intent = core.intent.take(tool, args)
|
|
195
|
+
if intent:
|
|
196
|
+
core.set_intent(intent)
|
|
197
|
+
# A feedback tool reached through the wrapper: the same span, counter,
|
|
198
|
+
# log line and hook as a direct call. The wrapper maps the SDK's reply to
|
|
199
|
+
# its own return type: the content items pass through, and a refusal
|
|
200
|
+
# becomes the library's tool error, so the agent sees isError either way.
|
|
201
|
+
if tool in core.feedback.tool_names():
|
|
202
|
+
result = core.record_feedback(tool, args)
|
|
203
|
+
if result.get("isError"):
|
|
204
|
+
raise ToolError(result["content"][0]["text"])
|
|
205
|
+
return [TextContent(**item) for item in result["content"]]
|
|
206
|
+
with core.tool_span(tool, args) as run: # one execute_tool span per real tool
|
|
207
|
+
try:
|
|
208
|
+
result = run_tool(tool, args)
|
|
209
|
+
except ToolFailed as exc:
|
|
210
|
+
run.set_error(type(exc).__name__, str(exc))
|
|
211
|
+
return {"error": str(exc)}
|
|
212
|
+
run.set_result(result)
|
|
213
|
+
return result
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`oodle_sdk.semconv` names every attribute, event and metric the SDK records
|
|
217
|
+
(`GEN_AI_TOOL_CALL_INTENT`, `ERROR_TYPE`, `TOOL_ERROR`,
|
|
218
|
+
`EVENT_GEN_AI_FEEDBACK`, ...), so a host that reads or writes them imports
|
|
219
|
+
them from one place.
|
|
220
|
+
|
|
221
|
+
A host with several servers in one process instruments each one. A server
|
|
222
|
+
whose listing must stay exactly as it is (a code runner whose scripts reach
|
|
223
|
+
the feedback tools through another server) gets `feedback=False`; a server
|
|
224
|
+
whose own instructions already ask for an intent and for reports gets
|
|
225
|
+
`augment_instructions=False`. With intent on, every listed tool without the
|
|
226
|
+
property gains it, about 60 characters per tool; a host with a token budget
|
|
227
|
+
names the tools that keep their schema in
|
|
228
|
+
`IntentConfig(exclude_tools={"ping", "health"})`.
|
|
229
|
+
|
|
230
|
+
## Attributes
|
|
231
|
+
|
|
232
|
+
The contract is
|
|
233
|
+
[`spec/mcp/attributes.md`](https://github.com/oodle-ai/oodle-sdk/blob/main/spec/mcp/attributes.md).
|
|
234
|
+
**Proposed** names have no convention yet
|
|
235
|
+
([draft proposal](https://github.com/oodle-ai/oodle-sdk/blob/main/spec/upstream/semconv-proposal.md));
|
|
236
|
+
they are all in `oodle_sdk.semconv`, so an upstream rename is one change.
|
|
237
|
+
|
|
238
|
+
| Attribute | On | Source |
|
|
239
|
+
| --- | --- | --- |
|
|
240
|
+
| `mcp.method.name`, `jsonrpc.request.id`, `mcp.protocol.version`, `mcp.session.id` | server, client | semconv |
|
|
241
|
+
| `gen_ai.operation.name` (`execute_tool`), `gen_ai.tool.name`, `gen_ai.tool.call.arguments`, `gen_ai.tool.call.result` | `tools/call` | semconv |
|
|
242
|
+
| `gen_ai.tool.call.intent` | `tools/call`, `execute_tool` | **proposed** |
|
|
243
|
+
| `gen_ai.prompt.name`, `gen_ai.prompt.variables` | `prompts/get` | semconv |
|
|
244
|
+
| `mcp.resource.uri` | resource methods | semconv |
|
|
245
|
+
| `mcp.resource.contents` | `resources/read` | **proposed** |
|
|
246
|
+
| `rpc.status_code`, `error.type` | failures | semconv |
|
|
247
|
+
| `network.transport`, `network.protocol.name`, `network.protocol.version` | server, client | semconv |
|
|
248
|
+
| `client.address`, `user_agent.original`, `mcp.client.name`, `mcp.client.version` | server | semconv |
|
|
249
|
+
| `server.address`, `server.port` | client, HTTP | semconv |
|
|
250
|
+
| `gen_ai.feedback.id`, `.type`, `.category`, `.severity`, `.summary`, `.tool.name`, `.tool.call.arguments`, `.actual`, `.expected`, `.proposal`, `.workaround`, `.model`; the `gen_ai.feedback` event; the `gen_ai.feedback.reports` counter | feedback | **proposed** |
|
|
251
|
+
|
|
252
|
+
Metrics: `mcp.server.operation.duration`, `mcp.client.operation.duration`,
|
|
253
|
+
`mcp.server.session.duration`, `mcp.client.session.duration` (histograms in
|
|
254
|
+
seconds, semconv) and `gen_ai.feedback.reports` (counter, proposed). A tool
|
|
255
|
+
or prompt name the server did not register becomes `_OTHER` on a metric.
|
|
256
|
+
|
|
257
|
+
## Content capture is on by default
|
|
258
|
+
|
|
259
|
+
The SDK records tool arguments, tool results, prompt arguments and resource
|
|
260
|
+
contents on spans, cut to `max_content_chars` and with credential-like keys
|
|
261
|
+
and `Bearer`/`Basic` values redacted. Redaction by key name cannot find every
|
|
262
|
+
secret: when the spans leave your own systems, review what your tools carry,
|
|
263
|
+
or turn capture off with `McpConfig(capture_content=False)`,
|
|
264
|
+
`OODLE_MCP_CAPTURE_CONTENT=false` or
|
|
265
|
+
`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false`.
|
|
266
|
+
|
|
267
|
+
## Logging
|
|
268
|
+
|
|
269
|
+
One INFO line per feedback report on the logger `oodle_sdk.mcp.feedback`
|
|
270
|
+
(`log_reports=False` turns it off), and WARNING lines about configuration
|
|
271
|
+
faults and skipped messages on `oodle_sdk.mcp`, at most one per minute.
|
|
272
|
+
|
|
273
|
+
## Develop
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
cd python
|
|
277
|
+
uv sync
|
|
278
|
+
uv run pytest
|
|
279
|
+
uv run ruff check . && uv run ruff format --check .
|
|
280
|
+
uv run mypy && uv run pyright
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The fixture tests read `../spec/fixtures/*.json`; change a fixture before you
|
|
284
|
+
change behaviour. The live tests in `tests/live` need an MCP library and skip
|
|
285
|
+
without one: `uv run --with "mcp>=2" python -m pytest tests/live`, or
|
|
286
|
+
`--with "mcp<2"`, or `--with "fastmcp>=2,<3"` (`python -m pytest`, because a
|
|
287
|
+
bare `pytest` script can run in the project environment without the
|
|
288
|
+
`--with` package and skip every test). `uv run --with "mcp<2" python
|
|
289
|
+
benchmarks/overhead.py` measures the latency the SDK adds to one tool call.
|
|
290
|
+
Each library generation gives one SERVER span per request and one CLIENT span
|
|
291
|
+
per call: the SDK replaces the span middleware of `mcp` 2.x, turns the client
|
|
292
|
+
span of its dispatcher into a no-op, and sets `fastmcp` 4's `telemetry_mode`
|
|
293
|
+
to `off`.
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
Apache License 2.0.
|