cherry-studio/src/main/services/mcp/ServerLogBuffer.ts
LiuVaayne 96085707ce
feat: add MCP server log viewer (#11826)
*  feat: add MCP server log viewer

* 🧹 chore: format files

* 🐛 fix: resolve MCP log viewer type errors

* 🧹 chore: sync i18n for MCP log viewer

* 💄 fix: improve MCP log modal contrast in dark mode

* 🌐 fix: translate MCP log viewer strings

Add translations for noLogs and viewLogs keys in:
- German (de-de)
- Greek (el-gr)
- Spanish (es-es)
- French (fr-fr)
- Japanese (ja-jp)
- Portuguese (pt-pt)
- Russian (ru-ru)

* 🌐 fix: update MCP log viewer translations and key references

Added "logs" key to various language files and updated references in the MCP settings component to improve consistency across translations. This includes updates for English, Chinese (Simplified and Traditional), German, Greek, Spanish, French, Japanese, Portuguese, and Russian.

---------

Co-authored-by: kangfenmao <kangfenmao@qq.com>
2025-12-11 11:18:56 +08:00

37 lines
861 B
TypeScript

export type MCPServerLogEntry = {
timestamp: number
level: 'debug' | 'info' | 'warn' | 'error' | 'stderr' | 'stdout'
message: string
data?: any
source?: string
}
/**
* Lightweight ring buffer for per-server MCP logs.
*/
export class ServerLogBuffer {
private maxEntries: number
private logs: Map<string, MCPServerLogEntry[]> = new Map()
constructor(maxEntries = 200) {
this.maxEntries = maxEntries
}
append(serverKey: string, entry: MCPServerLogEntry) {
const list = this.logs.get(serverKey) ?? []
list.push(entry)
if (list.length > this.maxEntries) {
list.splice(0, list.length - this.maxEntries)
}
this.logs.set(serverKey, list)
}
get(serverKey: string): MCPServerLogEntry[] {
return [...(this.logs.get(serverKey) ?? [])]
}
remove(serverKey: string) {
this.logs.delete(serverKey)
}
}