docs: update MCP examples (#3342)
This commit is contained in:
+11
-7
@@ -83,19 +83,23 @@ from agents import Agent, HostedMCPTool, Runner
|
||||
async def main() -> None:
|
||||
agent = Agent(
|
||||
name="Assistant",
|
||||
instructions="Use the DeepWiki hosted MCP server to inspect openai/openai-agents-python.",
|
||||
tools=[
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "never",
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
result = await Runner.run(agent, "Which language is this repository written in?")
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
"Which language is the repository openai/openai-agents-python written in?",
|
||||
)
|
||||
print(result.final_output)
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -124,7 +128,7 @@ print(result.final_output)
|
||||
```python
|
||||
from agents import MCPToolApprovalFunctionResult, MCPToolApprovalRequest
|
||||
|
||||
SAFE_TOOLS = {"read_project_metadata"}
|
||||
SAFE_TOOLS = {"read_wiki_structure", "read_wiki_contents", "ask_question"}
|
||||
|
||||
def approve_tool(request: MCPToolApprovalRequest) -> MCPToolApprovalFunctionResult:
|
||||
if request.data.name in SAFE_TOOLS:
|
||||
@@ -137,8 +141,8 @@ agent = Agent(
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "always",
|
||||
},
|
||||
on_approval_request=approve_tool,
|
||||
@@ -459,4 +463,4 @@ agent = Agent(
|
||||
|
||||
- [Model Context Protocol](https://modelcontextprotocol.io/) – 仕様と設計ガイド。
|
||||
- [examples/mcp](https://github.com/openai/openai-agents-python/tree/main/examples/mcp) – 実行可能な stdio、SSE、Streamable HTTP サンプル。
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 承認とコネクターを含む完全なホスト型 MCP デモ。
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 承認とコネクターを含む完全なホスト型 MCP デモ。
|
||||
|
||||
+11
-7
@@ -85,19 +85,23 @@ from agents import Agent, HostedMCPTool, Runner
|
||||
async def main() -> None:
|
||||
agent = Agent(
|
||||
name="Assistant",
|
||||
instructions="Use the DeepWiki hosted MCP server to inspect openai/openai-agents-python.",
|
||||
tools=[
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "never",
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
result = await Runner.run(agent, "Which language is this repository written in?")
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
"Which language is the repository openai/openai-agents-python written in?",
|
||||
)
|
||||
print(result.final_output)
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -126,7 +130,7 @@ print(result.final_output)
|
||||
```python
|
||||
from agents import MCPToolApprovalFunctionResult, MCPToolApprovalRequest
|
||||
|
||||
SAFE_TOOLS = {"read_project_metadata"}
|
||||
SAFE_TOOLS = {"read_wiki_structure", "read_wiki_contents", "ask_question"}
|
||||
|
||||
def approve_tool(request: MCPToolApprovalRequest) -> MCPToolApprovalFunctionResult:
|
||||
if request.data.name in SAFE_TOOLS:
|
||||
@@ -139,8 +143,8 @@ agent = Agent(
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "always",
|
||||
},
|
||||
on_approval_request=approve_tool,
|
||||
@@ -464,4 +468,4 @@ agent = Agent(
|
||||
|
||||
- [Model Context Protocol](https://modelcontextprotocol.io/) – 사양 및 설계 가이드
|
||||
- [examples/mcp](https://github.com/openai/openai-agents-python/tree/main/examples/mcp) – 실행 가능한 stdio, SSE, Streamable HTTP 샘플
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 승인과 커넥터를 포함한 완전한 호스티드 MCP 데모
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 승인과 커넥터를 포함한 완전한 호스티드 MCP 데모
|
||||
|
||||
+10
-6
@@ -85,19 +85,23 @@ from agents import Agent, HostedMCPTool, Runner
|
||||
async def main() -> None:
|
||||
agent = Agent(
|
||||
name="Assistant",
|
||||
instructions="Use the DeepWiki hosted MCP server to inspect openai/openai-agents-python.",
|
||||
tools=[
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "never",
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
result = await Runner.run(agent, "Which language is this repository written in?")
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
"Which language is the repository openai/openai-agents-python written in?",
|
||||
)
|
||||
print(result.final_output)
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -129,7 +133,7 @@ policies. To make the decision inside Python, provide an `on_approval_request` c
|
||||
```python
|
||||
from agents import MCPToolApprovalFunctionResult, MCPToolApprovalRequest
|
||||
|
||||
SAFE_TOOLS = {"read_project_metadata"}
|
||||
SAFE_TOOLS = {"read_wiki_structure", "read_wiki_contents", "ask_question"}
|
||||
|
||||
def approve_tool(request: MCPToolApprovalRequest) -> MCPToolApprovalFunctionResult:
|
||||
if request.data.name in SAFE_TOOLS:
|
||||
@@ -142,8 +146,8 @@ agent = Agent(
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "always",
|
||||
},
|
||||
on_approval_request=approve_tool,
|
||||
|
||||
+11
-7
@@ -84,19 +84,23 @@ from agents import Agent, HostedMCPTool, Runner
|
||||
async def main() -> None:
|
||||
agent = Agent(
|
||||
name="Assistant",
|
||||
instructions="Use the DeepWiki hosted MCP server to inspect openai/openai-agents-python.",
|
||||
tools=[
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "never",
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
result = await Runner.run(agent, "Which language is this repository written in?")
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
"Which language is the repository openai/openai-agents-python written in?",
|
||||
)
|
||||
print(result.final_output)
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -126,7 +130,7 @@ print(result.final_output)
|
||||
```python
|
||||
from agents import MCPToolApprovalFunctionResult, MCPToolApprovalRequest
|
||||
|
||||
SAFE_TOOLS = {"read_project_metadata"}
|
||||
SAFE_TOOLS = {"read_wiki_structure", "read_wiki_contents", "ask_question"}
|
||||
|
||||
def approve_tool(request: MCPToolApprovalRequest) -> MCPToolApprovalFunctionResult:
|
||||
if request.data.name in SAFE_TOOLS:
|
||||
@@ -139,8 +143,8 @@ agent = Agent(
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "always",
|
||||
},
|
||||
on_approval_request=approve_tool,
|
||||
@@ -466,4 +470,4 @@ agent = Agent(
|
||||
|
||||
- [Model Context Protocol](https://modelcontextprotocol.io/) – 规范和设计指南。
|
||||
- [examples/mcp](https://github.com/openai/openai-agents-python/tree/main/examples/mcp) – 可运行的 stdio、SSE 和 Streamable HTTP 示例。
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 完整的托管 MCP 演示,包括审批和连接器。
|
||||
- [examples/hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp) – 完整的托管 MCP 演示,包括审批和连接器。
|
||||
|
||||
@@ -11,14 +11,14 @@ async def main(verbose: bool, stream: bool, repo: str):
|
||||
question = f"Which language is the repository {repo} written in?"
|
||||
agent = Agent(
|
||||
name="Assistant",
|
||||
instructions=f"You can use the hosted MCP server to inspect {repo}.",
|
||||
instructions=f"You can use the DeepWiki hosted MCP server to inspect {repo}.",
|
||||
model_settings=ModelSettings(tool_choice="required"),
|
||||
tools=[
|
||||
HostedMCPTool(
|
||||
tool_config={
|
||||
"type": "mcp",
|
||||
"server_label": "gitmcp",
|
||||
"server_url": "https://gitmcp.io/openai/codex",
|
||||
"server_label": "deepwiki",
|
||||
"server_url": "https://mcp.deepwiki.com/mcp",
|
||||
"require_approval": "never",
|
||||
}
|
||||
)
|
||||
@@ -35,7 +35,7 @@ async def main(verbose: bool, stream: bool, repo: str):
|
||||
else:
|
||||
run_result = await Runner.run(agent, question)
|
||||
print(run_result.final_output)
|
||||
# The repository is primarily written in multiple languages, including Rust and TypeScript...
|
||||
# The repository is primarily written in Python...
|
||||
|
||||
if verbose:
|
||||
for item in run_result.new_items:
|
||||
@@ -49,7 +49,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument(
|
||||
"--repo",
|
||||
default="https://github.com/openai/openai-agents-python",
|
||||
help="Repository URL or slug that the Git MCP server should use.",
|
||||
help="Repository URL or slug that the DeepWiki MCP server should use.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# MCP SSE Remote Example
|
||||
|
||||
Python port of the JS `examples/mcp/sse-example.ts`. It connects to a remote MCP
|
||||
server over SSE (`https://gitmcp.io/openai/codex`) and lets the agent use those tools.
|
||||
Python port of the JS `examples/mcp/sse-example.ts`. By default it starts the
|
||||
bundled local SSE MCP server and lets the agent use those tools. Set
|
||||
`MCP_SSE_REMOTE_URL` to try a compatible remote SSE server instead.
|
||||
|
||||
Run it with:
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# MCP Streamable HTTP Remote Example
|
||||
|
||||
Python port of the JS `examples/mcp/streamable-http-example.ts`. It connects to a
|
||||
remote MCP server over the Streamable HTTP transport (`https://gitmcp.io/openai/codex`)
|
||||
and lets the agent use those tools.
|
||||
Python port of the JS `examples/mcp/streamable-http-example.ts`. It connects to
|
||||
DeepWiki over the Streamable HTTP transport (`https://mcp.deepwiki.com/mcp`) and
|
||||
lets the agent use those tools.
|
||||
|
||||
Run it with:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user