MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / main

Function main

examples/agents_comprehensive.py:17–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def main() -> None:
18 anthropic = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
19
20 github_token = os.environ.get("GITHUB_TOKEN")
21 if not github_token:
22 raise RuntimeError("GITHUB_TOKEN is required (use a fine-grained PAT with public-repo read only)")
23
24 # Create an environment
25 environment = anthropic.beta.environments.create(
26 name="comprehensive-example-environment",
27 )
28 print("Created environment:", environment.id)
29
30 # Create a vault and store the MCP server credential in it
31 vault = anthropic.beta.vaults.create(display_name="comprehensive-example-vault")
32 print("Created vault:", vault.id)
33
34 credential = anthropic.beta.vaults.credentials.create(
35 vault.id,
36 display_name="github-mcp",
37 auth={
38 "type": "static_bearer",
39 "mcp_server_url": MCP_SERVER_URL,
40 "token": github_token,
41 },
42 )
43 print("Created credential:", credential.id)
44
45 # Upload a custom skill
46 skill_md_path = os.path.join(os.path.dirname(__file__), "greeting-SKILL.md")
47 with open(skill_md_path, "rb") as skill_file:
48 skill = anthropic.beta.skills.create(
49 display_title=f"comprehensive-greeting-{int(time.time() * 1000)}",
50 files=[("greeting/SKILL.md", skill_file, "text/markdown")],
51 )
52 print("Created skill:", skill.id)
53
54 # Create v1 of the agent with the built-in toolset, an MCP server, and a custom tool
55 agent_v1 = anthropic.beta.agents.create(
56 name="comprehensive-example-agent",
57 model="claude-sonnet-5",
58 system="You are a helpful assistant.",
59 mcp_servers=[{"type": "url", "name": MCP_SERVER_NAME, "url": MCP_SERVER_URL}],
60 tools=[
61 {"type": "agent_toolset_20260401"},
62 {"type": "mcp_toolset", "mcp_server_name": MCP_SERVER_NAME},
63 {
64 "type": "custom",
65 "name": "get_weather",
66 "description": "Look up the current weather for a city.",
67 "input_schema": {
68 "type": "object",
69 "properties": {"city": {"type": "string"}},
70 "required": ["city"],
71 },
72 },
73 ],
74 )

Callers 1

Calls 8

AnthropicClass · 0.90
to_jsonMethod · 0.80
getMethod · 0.45
createMethod · 0.45
updateMethod · 0.45
listMethod · 0.45
sendMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected