|
1 | 1 | from __future__ import annotations as _annotations
|
2 | 2 |
|
3 | 3 | import inspect
|
| 4 | +import warnings |
4 | 5 | from abc import ABC, abstractmethod
|
5 | 6 | from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Iterator, Mapping, Sequence
|
6 | 7 | from contextlib import AbstractAsyncContextManager, asynccontextmanager, contextmanager
|
7 | 8 | from types import FrameType
|
8 | 9 | from typing import TYPE_CHECKING, Any, Generic, TypeAlias, cast, overload
|
9 | 10 |
|
10 |
| -from typing_extensions import Self, TypeIs, TypeVar |
| 11 | +from typing_extensions import TypeIs, TypeVar |
11 | 12 |
|
12 | 13 | from pydantic_graph import End
|
13 | 14 | from pydantic_graph._utils import get_event_loop
|
14 | 15 |
|
15 |
| -from .. import ( |
16 |
| - _agent_graph, |
17 |
| - _system_prompt, |
18 |
| - _utils, |
19 |
| - exceptions, |
20 |
| - messages as _messages, |
21 |
| - models, |
22 |
| - result, |
23 |
| - usage as _usage, |
24 |
| -) |
| 16 | +from .. import _agent_graph, _system_prompt, _utils, exceptions, messages as _messages, models, result, usage as _usage |
25 | 17 | from .._tool_manager import ToolManager
|
26 | 18 | from ..output import OutputDataT, OutputSpec
|
27 | 19 | from ..result import AgentStream, FinalResult, StreamedRunResult
|
|
42 | 34 | from fasta2a.broker import Broker
|
43 | 35 | from fasta2a.schema import AgentProvider, Skill
|
44 | 36 | from fasta2a.storage import Storage
|
| 37 | + from mcp.server.lowlevel import Server |
45 | 38 | from starlette.middleware import Middleware
|
46 | 39 | from starlette.routing import BaseRoute, Route
|
47 | 40 | from starlette.types import ExceptionHandler, Lifespan
|
@@ -940,8 +933,28 @@ def to_a2a(
|
940 | 933 | lifespan=lifespan,
|
941 | 934 | )
|
942 | 935 |
|
| 936 | + def to_mcp( |
| 937 | + self, |
| 938 | + *, |
| 939 | + server_name: str | None = None, |
| 940 | + tool_name: str | None = None, |
| 941 | + tool_description: str | None = None, |
| 942 | + deps: AgentDepsT = None, |
| 943 | + ) -> Server: |
| 944 | + from .._mcp import agent_to_mcp |
| 945 | + |
| 946 | + warnings.warn('The `to_mcp` method is experimental, and may change in the future.', UserWarning) |
| 947 | + |
| 948 | + return agent_to_mcp( |
| 949 | + self, |
| 950 | + server_name=server_name, |
| 951 | + tool_name=tool_name, |
| 952 | + tool_description=tool_description, |
| 953 | + deps=deps, |
| 954 | + ) |
| 955 | + |
943 | 956 | async def to_cli(
|
944 |
| - self: Self, |
| 957 | + self, |
945 | 958 | deps: AgentDepsT = None,
|
946 | 959 | prog_name: str = 'pydantic-ai',
|
947 | 960 | message_history: list[_messages.ModelMessage] | None = None,
|
@@ -978,7 +991,7 @@ async def main():
|
978 | 991 | )
|
979 | 992 |
|
980 | 993 | def to_cli_sync(
|
981 |
| - self: Self, |
| 994 | + self, |
982 | 995 | deps: AgentDepsT = None,
|
983 | 996 | prog_name: str = 'pydantic-ai',
|
984 | 997 | message_history: list[_messages.ModelMessage] | None = None,
|
|
0 commit comments