-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathgithub_toolset.py
More file actions
59 lines (48 loc) · 1.52 KB
/
github_toolset.py
File metadata and controls
59 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""GitHub MCP toolset construction for tool call evaluation."""
import os
from typing import Any
import opik
from pydantic_ai.mcp import MCPServerStreamableHTTP
def build_github_toolset() -> MCPServerStreamableHTTP:
"""Build a real GitHub MCP toolset.
Returns:
A GitHub MCP toolset.
"""
token = os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN")
if not token:
msg = (
"Missing GitHub MCP configuration. "
"Set GITHUB_PERSONAL_ACCESS_TOKEN before running tool-call eval."
)
raise RuntimeError(msg)
# spellchecker:ignore-next-line
headers = {"Authorization": f"Bearer {token}"}
async def process_tool_call(
_ctx: Any,
call_tool: Any,
name: str,
args: dict[str, Any],
) -> Any:
"""Process a tool call.
Args:
_ctx: The context.
call_tool: The call tool.
name: The name of the tool.
args: The arguments of the tool.
Returns:
The result of the tool call.
"""
raw_args = args if isinstance(args, dict) else {}
with opik.start_as_current_span(
name=name,
type="tool",
input=raw_args,
metadata={"provider": "github_mcp", "mocked": False},
):
return await call_tool(name, raw_args)
return MCPServerStreamableHTTP(
"https://api.githubcopilot.com/mcp/",
timeout=60,
headers=headers,
process_tool_call=process_tool_call,
)