-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(client): display server stderr logs in Console tab #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Julien-ser
wants to merge
2
commits into
modelcontextprotocol:main
Choose a base branch
from
Julien-ser:fix/capture-server-stderr-logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−9
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,115 @@ | ||
| import { ServerNotification } from "@modelcontextprotocol/sdk/types.js"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { TabsContent } from "@/components/ui/tabs"; | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
||
| const ConsoleTab = () => ( | ||
| <TabsContent value="console" className="h-96"> | ||
| <div className="bg-gray-900 text-gray-100 p-4 rounded-lg h-full font-mono text-sm overflow-auto"> | ||
| <div className="opacity-50">Welcome to MCP Client Console</div> | ||
| {/* Console output would go here */} | ||
| </div> | ||
| </TabsContent> | ||
| ); | ||
| const LEVEL_COLORS: Record<string, string> = { | ||
| debug: "text-gray-400", | ||
| info: "text-green-400", | ||
| notice: "text-blue-300", | ||
| warning: "text-yellow-400", | ||
| warn: "text-yellow-400", | ||
| error: "text-red-400", | ||
| critical: "text-red-500", | ||
| alert: "text-orange-400", | ||
| emergency: "text-red-600", | ||
| }; | ||
|
|
||
| const ConsoleTab = ({ | ||
| serverLogs = [], | ||
| }: { | ||
| serverLogs?: ServerNotification[]; | ||
| }) => { | ||
| const bottomRef = useRef<HTMLDivElement>(null); | ||
| const [clearedCount, setClearedCount] = useState(0); | ||
|
|
||
| const allLogEntries = serverLogs.filter( | ||
| (n) => n.method === "notifications/message", | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| setClearedCount((currentClearedCount) => | ||
| Math.min(currentClearedCount, allLogEntries.length), | ||
| ); | ||
| }, [allLogEntries.length]); | ||
|
|
||
| const logEntries = allLogEntries.slice(clearedCount); | ||
|
|
||
| useEffect(() => { | ||
| bottomRef.current?.scrollIntoView({ behavior: "smooth" }); | ||
| }, [logEntries.length]); | ||
|
Comment on lines
+18
to
+40
|
||
|
|
||
| return ( | ||
| <TabsContent value="console" className="h-96"> | ||
| <div className="flex flex-col h-full bg-gray-900 rounded-lg overflow-hidden"> | ||
| <div className="flex items-center justify-between px-4 py-2 border-b border-gray-700"> | ||
| <span className="text-xs text-gray-400 font-mono"> | ||
| Server Logs (stderr / MCP logging) | ||
| </span> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={() => setClearedCount(allLogEntries.length)} | ||
| disabled={logEntries.length === 0} | ||
| className="text-gray-400 hover:text-gray-200 h-6 text-xs" | ||
| > | ||
| Clear | ||
| </Button> | ||
| </div> | ||
| <div className="flex-1 overflow-auto p-3 font-mono text-sm"> | ||
| {logEntries.length === 0 ? ( | ||
| <div className="text-gray-500 opacity-50 text-xs"> | ||
| No server logs yet. Stderr output and MCP logging notifications | ||
| will appear here. | ||
| </div> | ||
| ) : ( | ||
| <div className="space-y-0.5"> | ||
| {logEntries.map((notification, index) => { | ||
| const params = notification.params as Record<string, unknown>; | ||
| const level = String(params?.level ?? "info").toLowerCase(); | ||
| const logger = String(params?.logger ?? ""); | ||
| const data = params?.data; | ||
|
|
||
| let message: string; | ||
| if (typeof data === "string") { | ||
| message = data; | ||
| } else if (typeof data === "object" && data !== null) { | ||
| const dataObj = data as Record<string, unknown>; | ||
| message = | ||
| typeof dataObj.message === "string" | ||
| ? dataObj.message | ||
| : JSON.stringify(data, null, 2); | ||
| } else { | ||
| message = String(data ?? ""); | ||
| } | ||
|
|
||
| const colorClass = LEVEL_COLORS[level] ?? "text-gray-100"; | ||
|
|
||
| return ( | ||
| <div key={index} className="flex gap-2 leading-5"> | ||
| <span className="text-gray-500 select-none shrink-0 text-xs"> | ||
| [{level.toUpperCase().slice(0, 7).padEnd(7)}] | ||
| </span> | ||
| {logger && logger !== "stdio" && ( | ||
| <span className="text-gray-600 select-none shrink-0 text-xs"> | ||
| [{logger}] | ||
| </span> | ||
| )} | ||
| <span | ||
| className={`${colorClass} break-all whitespace-pre-wrap`} | ||
| > | ||
| {message} | ||
| </span> | ||
| </div> | ||
| ); | ||
| })} | ||
| <div ref={bottomRef} /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </TabsContent> | ||
| ); | ||
| }; | ||
|
|
||
| export default ConsoleTab; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.