adcp 1.0.3__py3-none-any.whl → 1.0.4__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.
adcp/__init__.py CHANGED
@@ -46,7 +46,7 @@ from adcp.types.generated import (
46
46
  UpdateMediaBuyResponse,
47
47
  )
48
48
 
49
- __version__ = "1.0.3"
49
+ __version__ = "1.0.4"
50
50
 
51
51
  __all__ = [
52
52
  # Client classes
adcp/protocols/mcp.py CHANGED
@@ -186,6 +186,40 @@ class MCPAdapter(ProtocolAdapter):
186
186
  else:
187
187
  raise ValueError(f"Unsupported transport scheme: {parsed.scheme}")
188
188
 
189
+ def _serialize_mcp_content(self, content: list[Any]) -> list[dict[str, Any]]:
190
+ """
191
+ Convert MCP SDK content objects to plain dicts.
192
+
193
+ The MCP SDK returns Pydantic objects (TextContent, ImageContent, etc.)
194
+ but the rest of the ADCP client expects protocol-agnostic dicts.
195
+ This method handles the translation at the protocol boundary.
196
+
197
+ Args:
198
+ content: List of MCP content items (may be dicts or Pydantic objects)
199
+
200
+ Returns:
201
+ List of plain dicts representing the content
202
+ """
203
+ result = []
204
+ for item in content:
205
+ # Already a dict, pass through
206
+ if isinstance(item, dict):
207
+ result.append(item)
208
+ # Pydantic v2 model with model_dump()
209
+ elif hasattr(item, "model_dump"):
210
+ result.append(item.model_dump())
211
+ # Pydantic v1 model with dict()
212
+ elif hasattr(item, "dict") and callable(item.dict):
213
+ result.append(item.dict())
214
+ # Fallback: try to access __dict__
215
+ elif hasattr(item, "__dict__"):
216
+ result.append(dict(item.__dict__))
217
+ # Last resort: serialize as unknown type
218
+ else:
219
+ logger.warning(f"Unknown MCP content type: {type(item)}, serializing as string")
220
+ result.append({"type": "unknown", "data": str(item)})
221
+ return result
222
+
189
223
  async def _call_mcp_tool(self, tool_name: str, params: dict[str, Any]) -> TaskResult[Any]:
190
224
  """Call a tool using MCP protocol."""
191
225
  start_time = time.time() if self.agent_config.debug else None
@@ -205,12 +239,15 @@ class MCPAdapter(ProtocolAdapter):
205
239
  # Call the tool using MCP client session
206
240
  result = await session.call_tool(tool_name, params)
207
241
 
242
+ # Serialize MCP SDK types to plain dicts at protocol boundary
243
+ serialized_content = self._serialize_mcp_content(result.content)
244
+
208
245
  if self.agent_config.debug and start_time:
209
246
  duration_ms = (time.time() - start_time) * 1000
210
247
  debug_info = DebugInfo(
211
248
  request=debug_request,
212
249
  response={
213
- "content": result.content,
250
+ "content": serialized_content,
214
251
  "is_error": result.isError if hasattr(result, "isError") else False,
215
252
  },
216
253
  duration_ms=duration_ms,
@@ -220,7 +257,7 @@ class MCPAdapter(ProtocolAdapter):
220
257
  # For AdCP, we expect the data in the content
221
258
  return TaskResult[Any](
222
259
  status=TaskStatus.COMPLETED,
223
- data=result.content,
260
+ data=serialized_content,
224
261
  success=True,
225
262
  debug_info=debug_info,
226
263
  )
@@ -20,10 +20,13 @@ def parse_mcp_content(content: list[dict[str, Any]], response_type: type[T]) ->
20
20
  MCP tools return content as a list of content items:
21
21
  [{"type": "text", "text": "..."}, {"type": "resource", ...}]
22
22
 
23
+ The MCP adapter is responsible for serializing MCP SDK Pydantic objects
24
+ to plain dicts before calling this function.
25
+
23
26
  For AdCP, we expect JSON data in text content items.
24
27
 
25
28
  Args:
26
- content: MCP content array
29
+ content: MCP content array (list of plain dicts)
27
30
  response_type: Expected Pydantic model type
28
31
 
29
32
  Returns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adcp
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: Official Python client for the Ad Context Protocol (AdCP)
5
5
  Author-email: AdCP Community <maintainers@adcontextprotocol.org>
6
6
  License: Apache-2.0
@@ -1,4 +1,4 @@
1
- adcp/__init__.py,sha256=GtTKciZQ6kfkQlsM1s87zUIpkgRAU6bLfbEp2pSdBds,2512
1
+ adcp/__init__.py,sha256=3ARviLlJxnjYaDMIRFLceNsaES6z9ft81qKRYeq6Eq4,2512
2
2
  adcp/__main__.py,sha256=4rjwH3i52Dsy-Pb0hw5hapQuEG8-bW2tTKKB0HsVsSs,12716
3
3
  adcp/client.py,sha256=iIZUy5j25H48gGYlR_VuVsB9zP6SF1HtRssdPs2VJkc,24232
4
4
  adcp/config.py,sha256=Vsy7ZPOI8G3fB_i5Nk-CHbC7wdasCUWuKlos0fwA0kY,2017
@@ -6,17 +6,17 @@ adcp/exceptions.py,sha256=dNRMKV23DlkGKyB9Xmt6MtlhvDu1crjzD_en4nAEwDY,4399
6
6
  adcp/protocols/__init__.py,sha256=6UFwACQ0QadBUzy17wUROHqsJDp8ztPW2jzyl53Zh_g,262
7
7
  adcp/protocols/a2a.py,sha256=TN26ac98h2NUZTTs39Tyd6pVoS3k-sASuLKhLpdYV-A,12255
8
8
  adcp/protocols/base.py,sha256=Tdxg1hefWVDvRP7q3yYbtPlIfUr01luPG0oT773qi30,4906
9
- adcp/protocols/mcp.py,sha256=zdnW3RxjEUwWm7jbTzs73dfVywCq3f7fyhwND3w-f54,13081
9
+ adcp/protocols/mcp.py,sha256=JNJdouaDQ66H9pUtsaZtV8FWoLGf28QM29tOLESDxsk,14664
10
10
  adcp/types/__init__.py,sha256=3E_TJUXqQQFcjmSZZSPLwqBP3s_ijsH2LDeuOU-MP30,402
11
11
  adcp/types/core.py,sha256=w6CLD2K0riAHUnrktYmQV7qnkO-6Ab4-CN67YSagAE4,4731
12
12
  adcp/types/generated.py,sha256=KoILEa5Gg0tsjMYoqDEWulKvPzS0333L3qj75AHr4yI,50855
13
13
  adcp/types/tasks.py,sha256=Ae9TSwG2F7oWXTcl4TvLhAzinbQkHNGF1Pc0q8RMNNM,23424
14
14
  adcp/utils/__init__.py,sha256=uetvSJB19CjQbtwEYZiTnumJG11GsafQmXm5eR3hL7E,153
15
15
  adcp/utils/operation_id.py,sha256=wQX9Bb5epXzRq23xoeYPTqzu5yLuhshg7lKJZihcM2k,294
16
- adcp/utils/response_parser.py,sha256=s7gEfXwPbvYTSoGqkx0Lp3v9uJ9HlWC2BSic3nO4ZnM,3909
17
- adcp-1.0.3.dist-info/licenses/LICENSE,sha256=PF39NR3Ae8PLgBhg3Uxw6ju7iGVIf8hfv9LRWQdii_U,629
18
- adcp-1.0.3.dist-info/METADATA,sha256=nqAcBHeBflsdVV2QNlqIeq93B53PZqQ9DNCKBhJOdGw,12724
19
- adcp-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- adcp-1.0.3.dist-info/entry_points.txt,sha256=DQKpcGsJX8DtVI_SGApQ7tNvqUB4zkTLaTAEpFgmi3U,44
21
- adcp-1.0.3.dist-info/top_level.txt,sha256=T1_NF0GefncFU9v_k56oDwKSJREyCqIM8lAwNZf0EOs,5
22
- adcp-1.0.3.dist-info/RECORD,,
16
+ adcp/utils/response_parser.py,sha256=NQTLlbvmnM_tE4B5w3oB1Wshny1p-Uh8IWbghlwoNJc,4057
17
+ adcp-1.0.4.dist-info/licenses/LICENSE,sha256=PF39NR3Ae8PLgBhg3Uxw6ju7iGVIf8hfv9LRWQdii_U,629
18
+ adcp-1.0.4.dist-info/METADATA,sha256=ahZm1ty9AJ28PK5cC5_lrjkXPacgO3-3VMYn5ncfzJ4,12724
19
+ adcp-1.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ adcp-1.0.4.dist-info/entry_points.txt,sha256=DQKpcGsJX8DtVI_SGApQ7tNvqUB4zkTLaTAEpFgmi3U,44
21
+ adcp-1.0.4.dist-info/top_level.txt,sha256=T1_NF0GefncFU9v_k56oDwKSJREyCqIM8lAwNZf0EOs,5
22
+ adcp-1.0.4.dist-info/RECORD,,
File without changes