Skip to content

Commit 41c1983

Browse files
committed
agent: mcp tools sample
1 parent 356c164 commit 41c1983

File tree

11 files changed

+3252
-14
lines changed

11 files changed

+3252
-14
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UIPATH_MCP_SERVER_URL=***
2+
ANTHROPIC_API_KEY=***
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Agent Code Patterns Reference
2+
3+
This document provides practical code patterns for building UiPath coded agents using the UiPath Python SDK.
4+
5+
---
6+
7+
## Documentation Structure
8+
9+
This documentation is split into multiple files for efficient context loading. Load only the files you need:
10+
11+
1. **@.agent/REQUIRED_STRUCTURE.md** - Agent structure patterns and templates
12+
- **When to load:** Creating a new agent or understanding required patterns
13+
- **Contains:** Required Pydantic models (Input, Output), SDK initialization patterns, standard agent template
14+
15+
2. **@.agent/SDK_REFERENCE.md** - Complete SDK API reference
16+
- **When to load:** Calling UiPath SDK methods, working with services (actions, assets, jobs, etc.)
17+
- **Contains:** All SDK services and methods with full signatures and type annotations
18+
19+
3. **@.agent/CLI_REFERENCE.md** - CLI commands documentation
20+
- **When to load:** Working with `uipath init`, `uipath run`, or `uipath eval` commands
21+
- **Contains:** Command syntax, options, usage examples, and workflows
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# LangGraph Agent with Claude and Tool MCP Servers
2+
3+
This project demonstrates how to create an agent using LangGraph react agent which connects to a Remote MCP Server hosted in UiPath.
4+
5+
## Overview
6+
7+
The agent uses:
8+
- LangGraph for orchestration
9+
- Connects to a Remote MCP server
10+
11+
## Architecture
12+
13+
```mermaid
14+
---
15+
config:
16+
flowchart:
17+
curve: linear
18+
---
19+
graph TD;
20+
__start__([<p>__start__</p>]):::first
21+
agent(agent)
22+
tools(tools)
23+
__end__([<p>__end__</p>]):::last
24+
__start__ --> agent;
25+
tools --> agent;
26+
agent -.-> tools;
27+
agent -.-> __end__;
28+
classDef default fill:#f2f0ff,line-height:1.2
29+
classDef first fill-opacity:0
30+
classDef last fill:#bfb6fc
31+
```
32+
33+
The workflow follows a ReAct pattern:
34+
1. Query is sent to the agent (Claude)
35+
2. Agent decides whether to use tools or provide a final answer
36+
3. If tools are needed, the request is sent to the remote MCP server
37+
4. Results from tools are sent back to the agent
38+
5. Process repeats until the agent has enough information to provide a final answer
39+
40+
## Prerequisites
41+
42+
- Python 3.11+
43+
- `langchain-anthropic`
44+
- `langchain-mcp-adapters`
45+
- `langgraph`
46+
- Anthropic API key set as an environment variable
47+
48+
## Installation
49+
50+
```bash
51+
uv venv -p 3.11 .venv
52+
.venv\Scripts\activate
53+
uv sync
54+
```
55+
56+
Set your API keys and MCP Remote Server URL as environment variables in .env
57+
58+
```bash
59+
ANTHROPIC_API_KEY=your_anthropic_api_key
60+
```
61+
62+
## Debugging
63+
64+
For debugging issues:
65+
66+
1. Check logs for any connection or runtime errors:
67+
```bash
68+
uipath run agent --debug '{"messages": [{"type": "human", "content": "What is 2+2"}]}'
69+
```
70+
71+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "2.0",
3+
"resources": []
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://cloud.uipath.com/draft/2024-12/entry-point",
3+
"$id": "entry-points.json",
4+
"entryPoints": []
5+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
from contextlib import asynccontextmanager
2+
from datetime import datetime, timezone
3+
from typing import Sequence
4+
5+
from langchain_core.messages import HumanMessage, SystemMessage
6+
from langchain_core.tools import BaseTool
7+
from pydantic import BaseModel, Field
8+
from uipath.agent.models.agent import AgentMcpResourceConfig, AgentMcpTool
9+
from uipath.agent.react import AGENT_SYSTEM_PROMPT_TEMPLATE
10+
11+
from uipath_langchain.agent.react import create_agent
12+
from uipath_langchain.agent.tools import create_mcp_tools
13+
from uipath_langchain.chat import OpenAIModels, UiPathChat
14+
15+
# LLM Model Configuration
16+
llm = UiPathChat(
17+
model=OpenAIModels.gpt_5_mini_2025_08_07,
18+
temperature=0.0,
19+
max_tokens=16384,
20+
)
21+
22+
23+
# Input/Output Models
24+
class AgentInput(BaseModel):
25+
pass
26+
27+
28+
class AgentOutput(BaseModel):
29+
content: str | None = Field(None, description="Output content")
30+
31+
32+
# Agent Messages Function
33+
def create_messages(state: AgentInput) -> Sequence[SystemMessage | HumanMessage]:
34+
# Apply system prompt template
35+
current_date = datetime.now(timezone.utc).strftime("%Y-%m-%d")
36+
system_prompt_content = f"""You are an agentic assistant."""
37+
enhanced_system_prompt = (
38+
AGENT_SYSTEM_PROMPT_TEMPLATE.replace("{{systemPrompt}}", system_prompt_content)
39+
.replace("{{currentDate}}", current_date)
40+
.replace("{{agentName}}", "Mr Assistant")
41+
)
42+
43+
return [
44+
SystemMessage(content=enhanced_system_prompt),
45+
HumanMessage(content=f"""Do me an RPA echo of "asdf"."""),
46+
]
47+
48+
49+
mcpTools = [
50+
AgentMcpResourceConfig(
51+
name="uipath-server",
52+
description="a",
53+
folderPath="611ca479-1f38-4abc-b2c6-6a61fa002978",
54+
slug="uipath-server",
55+
availableTools=[],
56+
isEnabled=True,
57+
),
58+
AgentMcpResourceConfig(
59+
name="uipath-server-2",
60+
description="a",
61+
folderPath="611ca479-1f38-4abc-b2c6-6a61fa002978",
62+
slug="uipath-server-2",
63+
availableTools=[],
64+
isEnabled=True,
65+
),
66+
AgentMcpResourceConfig(
67+
name="hello-world",
68+
description="a",
69+
folderPath="611ca479-1f38-4abc-b2c6-6a61fa002978",
70+
slug="hello-world",
71+
availableTools=[],
72+
isEnabled=True,
73+
),
74+
AgentMcpResourceConfig(
75+
name="mcp-hello-world-24-25",
76+
description="a",
77+
folderPath="611ca479-1f38-4abc-b2c6-6a61fa002978",
78+
slug="mcp-hello-world-24-25",
79+
availableTools=[
80+
AgentMcpTool(
81+
name="add",
82+
description="""
83+
Add two numbers together.
84+
Args:
85+
a: First number
86+
b: Second number
87+
88+
Returns:
89+
Sum of a and b
90+
""",
91+
inputSchema={
92+
"type": "object",
93+
"properties": {
94+
"a": {"type": "number", "title": "A"},
95+
"b": {"type": "number", "title": "B"},
96+
},
97+
"required": ["a", "b"],
98+
},
99+
)
100+
],
101+
isEnabled=True,
102+
),
103+
]
104+
105+
all_tools: list[BaseTool] = []
106+
107+
108+
@asynccontextmanager
109+
async def make_graph():
110+
async with create_mcp_tools(mcpTools) as tools:
111+
yield create_agent(
112+
model=llm,
113+
tools=tools + all_tools,
114+
messages=create_messages,
115+
input_schema=AgentInput,
116+
output_schema=AgentOutput,
117+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[project]
2+
name = "simple-remote-mcp-agent"
3+
version = "0.0.1"
4+
description = "simple-remote-mcp-agent"
5+
authors = [{ name = "John Doe", email = "[email protected]" }]
6+
dependencies = [
7+
"langchain>=1.1.0",
8+
"langchain-anthropic>=1.2.0",
9+
"langgraph>=1.0.4",
10+
"python-dotenv>=1.0.0",
11+
"anthropic>=0.57.1",
12+
"langchain-mcp-adapters>=0.1.14",
13+
"uipath>=2.2.0, <2.3.0",
14+
"uipath-langchain>=0.1.30",
15+
]
16+
requires-python = ">=3.11"
17+
18+
[tool.setuptools]
19+
py-modules = []
20+
21+
[dependency-groups]
22+
dev = [
23+
"uipath-dev>=0.0.5",
24+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://cloud.uipath.com/draft/2024-12/uipath",
3+
"runtimeOptions": {
4+
"isConversational": false
5+
},
6+
"packOptions": {
7+
"fileExtensionsIncluded": [],
8+
"filesIncluded": [],
9+
"filesExcluded": [],
10+
"directoriesExcluded": [],
11+
"includeUvLock": true
12+
},
13+
"functions": {}
14+
}

0 commit comments

Comments
 (0)