Skip to content

Commit 0561543

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

File tree

6 files changed

+2578
-0
lines changed

6 files changed

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