avc-mcp-client
v0.1.1
Published
MCP client for AVC video enhancement service
Readme
AVC MCP Client (NPM)
NPM client for AVC video enhancement MCP service.
Installation
npm install avc-mcp-clientOr with yarn:
yarn add avc-mcp-clientOr with pnpm:
pnpm add avc-mcp-clientQuick Start
URL Video
import { AVCMCPClient } from 'avc-mcp-client';
// Initialize client
const client = new AVCMCPClient({
baseUrl: 'http://192.168.0.7:8001',
apiKey: 'your-api-key'
});
// Sync video enhancement (blocks until complete)
const result = await client.enhanceVideoSync({
videoUrl: 'https://example.com/video.mp4',
type: 'url', // default
resolution: '720p'
});
if (result.success) {
console.log(`Enhanced video: ${result.videoUrl}`);
}Local File (Node.js)
import { AVCMCPClient, validateFileSize } from 'avc-mcp-client';
import { readFileSync } from 'fs';
import { basename } from 'path';
const client = new AVCMCPClient({
baseUrl: 'http://192.168.0.7:8001',
apiKey: 'your-api-key'
});
// Read local file as base64
const filePath = '/path/to/video.mp4';
const fileData = readFileSync(filePath).toString('base64');
// Optional: validate file size (max 100MB)
validateFileSize(fileData, 100);
// Enhance local file
const result = await client.enhanceVideoSync({
videoUrl: basename(filePath), // filename
type: 'local',
fileData: fileData,
resolution: '720p'
});
if (result.success) {
console.log(`Enhanced video: ${result.videoUrl}`);
}API Reference
AVCMCPClient
Main client class for MCP service.
Constructor
new AVCMCPClient(options?: AVCMCPClientOptions)Options:
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| baseUrl | string | http://192.168.0.7:8001 | MCP server URL |
| apiKey | string | - | API key for authentication |
| timeout | number | 600000 (10 min) | Default timeout in ms |
| pollInterval | number | 5000 | Polling interval in ms |
Methods
enhanceVideoSync
Enhance video synchronously (blocks until complete).
await client.enhanceVideoSync({
videoUrl: string, // URL or filename
type?: 'url' | 'local', // default: 'url'
fileData?: string, // base64 data (required if type='local')
resolution?: Resolution, // default: '720p'
timeout?: number
}): Promise<EnhanceResult>enhanceVideoAsync
Start video enhancement asynchronously.
await client.enhanceVideoAsync({
videoUrl: string, // URL or filename
type?: 'url' | 'local', // default: 'url'
fileData?: string, // base64 data (required if type='local')
resolution?: Resolution
}): Promise<AsyncTaskResult>getTaskStatus
Query task status.
await client.getTaskStatus(taskId: string): Promise<TaskStatusResult>waitForTask
Wait for task completion.
await client.waitForTask(taskId: string, options?: {
timeout?: number, // default: 600000
pollInterval?: number // default: 5000
}): Promise<TaskStatusResult>Helper Functions
validateFileSize
Validate base64 file size (throws FileSizeExceededError if exceeded).
validateFileSize(base64Data: string, maxSizeMb?: number): voidTypes
Resolution
type Resolution = '480p' | '540p' | '720p' | '1080p' | '2k'VideoType
type VideoType = 'url' | 'local'TaskStatus
type TaskStatus = 'wait' | 'start' | 'processing' | 'completed' | 'failed' | 'timeout'AsyncTaskResult
interface AsyncTaskResult {
success: boolean;
taskId?: string; // 失败时可能为空
status?: TaskStatus;
message?: string;
error?: string;
}EnhanceResult
interface EnhanceResult {
success: boolean;
taskId?: string;
status?: TaskStatus;
videoUrl?: string;
message?: string;
error?: string;
}TaskStatusResult
interface TaskStatusResult {
success: boolean;
taskId?: string;
status?: TaskStatus;
videoUrl?: string;
message?: string;
error?: string;
}Exceptions
| Exception | Description |
|-----------|-------------|
| MCPClientError | Base exception |
| MCPConnectionError | Connection failed |
| MCPParseError | Response parsing failed |
| MCPToolError | Tool execution failed |
| MPCTimeoutError | Operation timed out |
| MCPAuthenticationError | Authentication failed |
| FileSizeExceededError | File size exceeds 100MB limit |
Example: Async Enhancement with Polling
import { AVCMCPClient, MPCTimeoutError } from 'avc-mcp-client';
const client = new AVCMCPClient({
baseUrl: 'http://192.168.0.7:8001',
apiKey: 'your-api-key'
});
// Start async enhancement
const task = await client.enhanceVideoAsync({
videoUrl: 'https://example.com/long-video.mp4',
resolution: '1080p'
});
if (!task.taskId) {
console.error('任务创建失败:', task.error || task.message);
process.exit(1);
}
console.log(`Task created: ${task.taskId}`);
// Wait for completion with custom timeout
try {
const result = await client.waitForTask(task.taskId, {
timeout: 1200000, // 20 minutes
pollInterval: 10000 // Check every 10 seconds
});
if (result.success) {
console.log(`Enhanced video: ${result.videoUrl}`);
} else {
console.log(`Task failed: ${result.error}`);
}
} catch (e) {
if (e instanceof MPCTimeoutError) {
console.log('Task did not complete in time');
} else {
throw e;
}
}Development
# Install dependencies
pnpm install
# Build
pnpm build
# Run tests
pnpm test
# Type check
pnpm typecheckRequirements
- Node.js >= 18.0.0
License
MIT
