Skip to content

Commit 9062bdb

Browse files
committed
Mcp samples for env server and long running
1 parent d9005f7 commit 9062bdb

File tree

6 files changed

+2581
-0
lines changed

6 files changed

+2581
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
## Parameters
37+
38+
### Common Parameters
39+
40+
- **progress_interval_seconds** - How often to send progress notifications (in seconds)
41+
- **enable_logs** - Whether to capture detailed logs during the operation
42+
43+
### Custom Delay Parameters
44+
45+
- **seconds** - Number of seconds to delay
46+
- **minutes** - Number of minutes to delay
47+
- **hours** - Number of hours to delay
48+
49+
## Response Format
50+
51+
### Completion Response
52+
53+
```json
54+
{
55+
"status": "completed",
56+
"operation_name": "One Minute Task",
57+
"duration_seconds": 60,
58+
"actual_elapsed_seconds": 60.1,
59+
"message": "One Minute Task completed successfully"
60+
}
61+
```
62+
63+
### Custom Task Response
64+
65+
```json
66+
{
67+
"status": "completed",
68+
"operation_name": "Custom Delay Task (2h 30m 0s)",
69+
"duration_seconds": 9000,
70+
"actual_elapsed_seconds": 9000.3,
71+
"duration_breakdown": {
72+
"hours": 2,
73+
"minutes": 30,
74+
"seconds": 0
75+
},
76+
"message": "Custom Delay Task (2h 30m 0s) completed successfully"
77+
}
78+
```
79+
80+
### Random Duration Task Response
81+
82+
```json
83+
{
84+
"status": "completed",
85+
"operation_name": "Random Duration Task (47.3s)",
86+
"duration_seconds": 47,
87+
"actual_elapsed_seconds": 47.1,
88+
"random_duration_seconds": 47.3,
89+
"max_duration_seconds": 100,
90+
"message": "Random Duration Task (47.3s) completed successfully"
91+
}
92+
```
93+
94+
### Error Response
95+
96+
```json
97+
{
98+
"status": "error",
99+
"operation_name": "One Hour Task",
100+
"error": "Operation interrupted",
101+
"message": "Error in One Hour Task: Operation interrupted"
102+
}
103+
```
104+
105+
## Progress Tracking and Notifications
106+
107+
The server provides real-time progress tracking during blocking operations:
108+
109+
1. **Real-time Progress Updates** - Continuous progress reports sent directly to clients via `ctx.report_progress()`
110+
2. **Client Log Messages** - Optional detailed messages sent directly to clients via `ctx.info()` (when `enable_logs=True`)
111+
3. **Error Notifications** - Immediate error messages sent directly to clients via `ctx.error()`
112+
4. **Completion Results** - Detailed results returned upon task completion
113+
114+
## Use Cases
115+
116+
- **Data Processing** - Long-running data transformation or analysis tasks with progress tracking
117+
- **File Operations** - Large file transfers, backups, or synchronization with completion confirmation
118+
- **System Maintenance** - Scheduled maintenance tasks with real-time status updates
119+
- **Integration Testing** - Simulating long-running external API calls with progress monitoring
120+
- **Batch Processing** - Processing queues or large datasets with completion results
121+
- **Deployment Operations** - Application deployments with step-by-step progress tracking
122+
- **Workflow Automation** - UiPath automation tasks that require timed delays with progress feedback
123+
124+
## Configuration
125+
126+
Standard MCP configuration files:
127+
128+
- `mcp.json` - Server transport and command configuration
129+
- `pyproject.toml` - Python project dependencies
130+
- `uipath.json` - UiPath platform integration settings
131+
132+
## Running the Server
133+
134+
```bash
135+
# Local debugging
136+
uipath run longrunning-server
137+
138+
# Package and deploy
139+
uipath pack
140+
uipath publish
141+
```
142+
143+
## Error Handling
144+
145+
The server includes comprehensive error handling:
146+
147+
- Invalid duration parameters with immediate error responses
148+
- Exception handling with detailed error messages sent to clients
149+
- Real-time error notifications via `ctx.error()`
150+
- Graceful error recovery with structured error responses
151+
152+
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)