Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.idea/

# Ruff stuff:
.ruff_cache/

Expand All @@ -178,4 +180,4 @@ cython_debug/
**/.uipath
**/**.nupkg
**/__uipath/
**/.langgraph_api
**/.langgraph_api
6 changes: 6 additions & 0 deletions .idea/ai_debugger.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/uipath-langchain-python.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions samples/oauth-external-apps-agent/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UIPATH_MCP_SERVER_URL=***
ANTHROPIC_API_KEY=***
UIPATH_TOKEN_URL=***
UIPATH_CLIENT_ID=***
UIPATH_CLIENT_SECRET=***
SCOPE=***
8 changes: 8 additions & 0 deletions samples/oauth-external-apps-agent/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions samples/oauth-external-apps-agent/.idea/ai_debugger.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions samples/oauth-external-apps-agent/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions samples/oauth-external-apps-agent/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions samples/oauth-external-apps-agent/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions samples/oauth-external-apps-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# LangGraph Agent with Claude, OAuth and Tool MCP Servers

This project demonstrates how to build a LangGraph agent powered by Claude 3.5 Sonnet that connects to a remote UiPath MCP server, using an external UiPath application to handle OAuth authentication.

## Overview

The agent uses:
- Claude 3.5 Sonnet as the language model
- LangGraph for orchestration
- Remote tool execution via UiPath MCP server.
- Dynamic access token refresh through client credentials grant (OAuth).

## Architecture

```mermaid
---
config:
flowchart:
curve: linear
---
graph TD;
__start__([<p>__start__</p>]):::first
fetch_new_access_token(fetch_new_access_token)
connect_to_mcp(connect_to_mcp)
collect_output(collect_output)
__end__([<p>__end__</p>]):::last
__start__ --> connect_to_mcp;
connect_to_mcp -.-> collect_output;
connect_to_mcp -.-> fetch_new_access_token;
fetch_new_access_token --> connect_to_mcp;
collect_output --> __end__;
connect_to_mcp -.-> connect_to_mcp;
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc

```

The workflow follows a ReAct pattern:
1. Query is sent to the agent (Claude)
2. The agent first attempts to connect to the remote MCP server using the current `UIPATH_ACCESS_TOKEN`.
3. If the token is missing or expired, the workflow triggers a call to the UiPath external application endpoint to fetch a fresh token and stores it in the environment.
4. Once connected, the MCP tools are loaded into a Claude-powered ReAct agent.
5. The agent receives both system context and the human task, deciding whether to invoke tools or provide a direct answer.
6. The process repeats until the agent has enough information to produce a final response.
7. The response is collected and returned as the workflow output.

## Prerequisites

- Python 3.10+
- `langchain-anthropic`
- `langchain-mcp-adapters`
- `langgraph`
- `httpx`
- `python-dotenv`
- Anthropic API key set as an environment variable
- UiPath OAuth credentials and MCP server URL in environment (`UIPATH_CLIENT_ID`, `UIPATH_CLIENT_SECRET`, `UIPATH_TOKEN_URL`, `UIPATH_MCP_SERVER_URL`, `SCOPE`)

## Installation

```bash
uv venv -p 3.11 .venv
.venv\Scripts\activate
uv sync
```

Set your API keys and MCP Remote Server URL as environment variables in .env

```bash
ANTHROPIC_API_KEY=your_anthropic_api_key
UIPATH_MCP_SERVER_URL=https://alpha.uipath.com/account/tenant/mcp_/mcp/server_slug/sse
UIPATH_TOKEN_URL=***
UIPATH_CLIENT_ID=***
UIPATH_CLIENT_SECRET=***
SCOPE=***

```

## Debugging

For debugging issues:

1. Check logs for any connection or runtime errors:
```bash
uipath run agent --debug '{"task": "What is 2 + 2?"}'
```


20 changes: 20 additions & 0 deletions samples/oauth-external-apps-agent/agent.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
config:
flowchart:
curve: linear
---
graph TD;
__start__([<p>__start__</p>]):::first
fetch_new_access_token(fetch_new_access_token)
connect_to_mcp(connect_to_mcp)
collect_output(collect_output)
__end__([<p>__end__</p>]):::last
__start__ --> connect_to_mcp;
connect_to_mcp -.-> collect_output;
connect_to_mcp -.-> fetch_new_access_token;
fetch_new_access_token --> connect_to_mcp;
collect_output --> __end__;
connect_to_mcp -.-> connect_to_mcp;
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc
1 change: 1 addition & 0 deletions samples/oauth-external-apps-agent/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "task": "What is 2+2" }
7 changes: 7 additions & 0 deletions samples/oauth-external-apps-agent/langgraph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": ["."],
"graphs": {
"agent": "./main.py:graph"
},
"env": ".env"
}
Loading
Loading