mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-09 06:43:08 +00:00
Add workflow-list, execution-history, and health-dashboard apps. Redesign operation-result with operation-aware headers, detail panels, and copy-to-clipboard. Fix React hooks violations in validation-summary and execution-history (useMemo after early returns). Add local preview harness for development. Update tests for 5-app config. Conceived by Romuald Członkowski - www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { useState, useCallback } from 'react';
|
|
import { useApp, useHostStyles } from '@modelcontextprotocol/ext-apps/react';
|
|
import type { App } from '@modelcontextprotocol/ext-apps/react';
|
|
|
|
interface UseToolDataResult<T> {
|
|
data: T | null;
|
|
error: string | null;
|
|
isConnected: boolean;
|
|
app: App | null;
|
|
toolName: string | null;
|
|
}
|
|
|
|
export function useToolData<T>(): UseToolDataResult<T> {
|
|
const [data, setData] = useState<T | null>(null);
|
|
|
|
const onAppCreated = useCallback((app: App) => {
|
|
app.ontoolresult = (result) => {
|
|
if (result?.content) {
|
|
const textItem = Array.isArray(result.content)
|
|
? result.content.find((c) => c.type === 'text')
|
|
: null;
|
|
if (textItem && 'text' in textItem) {
|
|
try {
|
|
setData(JSON.parse(textItem.text) as T);
|
|
} catch {
|
|
setData(textItem.text as unknown as T);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}, []);
|
|
|
|
const { app, isConnected, error } = useApp({
|
|
appInfo: { name: 'n8n-mcp-ui', version: '1.0.0' },
|
|
capabilities: {},
|
|
onAppCreated,
|
|
});
|
|
|
|
useHostStyles(app, app?.getHostContext());
|
|
|
|
const toolName = app?.getHostContext()?.toolInfo?.tool.name ?? null;
|
|
|
|
return {
|
|
data,
|
|
error: error?.message ?? null,
|
|
isConnected,
|
|
app,
|
|
toolName,
|
|
};
|
|
}
|