Skip to content

Commit 65eea99

Browse files
committed
Mcp samples for env server and long running
1 parent d9005f7 commit 65eea99

File tree

6 files changed

+2646
-0
lines changed

6 files changed

+2646
-0
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# Long Running Operations MCP Server
2+
3+
This sample demonstrates how to create an MCP server that handles long-running operations with real-time progress tracking and client notifications. All operations block until completion, providing synchronous execution with live progress updates.
4+
5+
## Overview
6+
7+
The Long Running Operations MCP Server provides tools for executing blocking tasks that take varying amounts of time, with real-time progress monitoring and optional detailed logging. Operations block until completion while providing continuous progress updates to clients. This is particularly useful for automation scenarios that involve time-consuming operations like data processing, file transfers, or system maintenance tasks.
8+
9+
## Features
10+
11+
### Core Tools
12+
13+
1. **run_one_second_task** - Execute a blocking 1-second task with progress tracking
14+
2. **run_one_minute_task** - Execute a blocking 1-minute task with progress tracking
15+
3. **run_one_hour_task** - Execute a blocking 1-hour task with progress tracking
16+
4. **run_custom_delay_task** - Execute a blocking task with custom duration (seconds, minutes, hours)
17+
5. **run_random_duration_task** - Execute a blocking task with random duration (0 to max_duration_seconds)
18+
19+
### Key Features
20+
21+
- **Blocking execution** - Operations block until completion, providing synchronous behavior
22+
- **Real-time progress notifications** - Direct client notifications via `ctx.report_progress()`
23+
- **Live client logging** - Messages sent directly to clients via `ctx.info()` and `ctx.error()`
24+
- **Configurable intervals** - Customizable progress update frequencies
25+
- **Completion results** - Detailed results returned upon task completion
26+
- **Optional detailed logging** - Enhanced logging during operation execution
27+
28+
## Installation
29+
30+
```bash
31+
uv venv -p 3.11 .venv
32+
.venv\Scripts\activate
33+
uv sync
34+
```
35+
36+
## Usage Examples
37+
38+
### Basic Operations
39+
40+
```python
41+
# Run a 1-second task with default settings (blocks until complete)
42+
result = run_one_second_task()
43+
# Returns: {"status": "completed", "operation_name": "One Second Task", ...}
44+
45+
# Run a 1-minute task with progress every 5 seconds and logging enabled
46+
result = run_one_minute_task(progress_interval_seconds=5, enable_logs=True)
47+
48+
# Run a 1-hour task with progress every 10 minutes
49+
result = run_one_hour_task(progress_interval_seconds=600, enable_logs=False)
50+
```
51+
52+
### Custom Duration Operations
53+
54+
```python
55+
# Run a task for 2 hours and 30 minutes (blocks until complete)
56+
result = run_custom_delay_task(hours=2, minutes=30, progress_interval_seconds=300, enable_logs=True)
57+
58+
# Run a task for 45 seconds with frequent progress updates
59+
result = run_custom_delay_task(seconds=45, progress_interval_seconds=5, enable_logs=True)
60+
61+
# Run a task for 1 day (24 hours) with hourly progress updates
62+
result = run_custom_delay_task(hours=24, progress_interval_seconds=3600, enable_logs=True)
63+
```
64+
65+
### Random Duration Operations
66+
67+
```python
68+
# Run a task for random duration up to 100 seconds (default)
69+
result = run_random_duration_task()
70+
71+
# Run a task for random duration up to 300 seconds with frequent progress updates
72+
result = run_random_duration_task(max_duration_seconds=300, progress_interval_seconds=5, enable_logs=True)
73+
74+
# Run a task for random duration up to 10 seconds
75+
result = run_random_duration_task(max_duration_seconds=10, progress_interval_seconds=2)
76+
```
77+
78+
### Operation Results
79+
80+
All operations return completion details immediately after finishing:
81+
82+
```python
83+
# Example successful completion
84+
{
85+
"status": "completed",
86+
"operation_name": "One Minute Task",
87+
"duration_seconds": 60,
88+
"actual_elapsed_seconds": 60.1,
89+
"message": "One Minute Task completed successfully"
90+
}
91+
92+
# Example error response
93+
{
94+
"status": "error",
95+
"operation_name": "Custom Delay Task",
96+
"error": "Operation interrupted",
97+
"message": "Error in Custom Delay Task: Operation interrupted"
98+
}
99+
```
100+
101+
## Parameters
102+
103+
### Common Parameters
104+
105+
- **progress_interval_seconds** - How often to send progress notifications (in seconds)
106+
- **enable_logs** - Whether to capture detailed logs during the operation
107+
108+
### Custom Delay Parameters
109+
110+
- **seconds** - Number of seconds to delay
111+
- **minutes** - Number of minutes to delay
112+
- **hours** - Number of hours to delay
113+
114+
## Response Format
115+
116+
### Completion Response
117+
118+
```json
119+
{
120+
"status": "completed",
121+
"operation_name": "One Minute Task",
122+
"duration_seconds": 60,
123+
"actual_elapsed_seconds": 60.1,
124+
"message": "One Minute Task completed successfully"
125+
}
126+
```
127+
128+
### Custom Task Response
129+
130+
```json
131+
{
132+
"status": "completed",
133+
"operation_name": "Custom Delay Task (2h 30m 0s)",
134+
"duration_seconds": 9000,
135+
"actual_elapsed_seconds": 9000.3,
136+
"duration_breakdown": {
137+
"hours": 2,
138+
"minutes": 30,
139+
"seconds": 0
140+
},
141+
"message": "Custom Delay Task (2h 30m 0s) completed successfully"
142+
}
143+
```
144+
145+
### Random Duration Task Response
146+
147+
```json
148+
{
149+
"status": "completed",
150+
"operation_name": "Random Duration Task (47.3s)",
151+
"duration_seconds": 47,
152+
"actual_elapsed_seconds": 47.1,
153+
"random_duration_seconds": 47.3,
154+
"max_duration_seconds": 100,
155+
"message": "Random Duration Task (47.3s) completed successfully"
156+
}
157+
```
158+
159+
### Error Response
160+
161+
```json
162+
{
163+
"status": "error",
164+
"operation_name": "One Hour Task",
165+
"error": "Operation interrupted",
166+
"message": "Error in One Hour Task: Operation interrupted"
167+
}
168+
```
169+
170+
## Progress Tracking and Notifications
171+
172+
The server provides real-time progress tracking during blocking operations:
173+
174+
1. **Real-time Progress Updates** - Continuous progress reports sent directly to clients via `ctx.report_progress()`
175+
2. **Client Log Messages** - Optional detailed messages sent directly to clients via `ctx.info()` (when `enable_logs=True`)
176+
3. **Error Notifications** - Immediate error messages sent directly to clients via `ctx.error()`
177+
4. **Completion Results** - Detailed results returned upon task completion
178+
179+
## Use Cases
180+
181+
- **Data Processing** - Long-running data transformation or analysis tasks with progress tracking
182+
- **File Operations** - Large file transfers, backups, or synchronization with completion confirmation
183+
- **System Maintenance** - Scheduled maintenance tasks with real-time status updates
184+
- **Integration Testing** - Simulating long-running external API calls with progress monitoring
185+
- **Batch Processing** - Processing queues or large datasets with completion results
186+
- **Deployment Operations** - Application deployments with step-by-step progress tracking
187+
- **Workflow Automation** - UiPath automation tasks that require timed delays with progress feedback
188+
189+
## Configuration
190+
191+
Standard MCP configuration files:
192+
193+
- `mcp.json` - Server transport and command configuration
194+
- `pyproject.toml` - Python project dependencies
195+
- `uipath.json` - UiPath platform integration settings
196+
197+
## Running the Server
198+
199+
```bash
200+
# Local debugging
201+
uipath run longrunning-server
202+
203+
# Package and deploy
204+
uipath pack
205+
uipath publish
206+
```
207+
208+
## Error Handling
209+
210+
The server includes comprehensive error handling:
211+
212+
- Invalid duration parameters with immediate error responses
213+
- Exception handling with detailed error messages sent to clients
214+
- Real-time error notifications via `ctx.error()`
215+
- Graceful error recovery with structured error responses
216+
217+
All operations block until completion or error, providing immediate feedback to clients.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"servers": {
3+
"longrunning-server": {
4+
"transport": "stdio",
5+
"command": "python",
6+
"args": ["server.py"]
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "mcp-longrunning-server"
3+
version = "0.0.1"
4+
description = "Long Running Operations MCP Server"
5+
authors = [{ name = "John Doe" }]
6+
dependencies = [
7+
"uipath-mcp>=0.0.78",
8+
]
9+
requires-python = ">=3.10"

0 commit comments

Comments
 (0)