Skip to content

feat(server): add get_console_logs tool to MCP Server Tools #33

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

Merged
merged 2 commits into from
May 20, 2025

Conversation

twilight07
Copy link
Contributor

@twilight07 twilight07 commented May 20, 2025

Description

This pull request adds a new tool called get_console_logs to the MCP Server Tools. The main purpose of this tool is to retrieve logs from the Unity console, providing a way to access console logs through the tools interface.

Key changes include:

  • Introduction of a new file getConsoleLogsTool.ts in the Server~/src/tools/ directory.
  • Registration of the new tool in the main index.ts file.
  • Reuse of the existing Unity-side implementation to minimize code changes.
  • Maintenance of the same functionality as the unity://logs resource.

The tool allows for optional filtering of log types (info, warning, error) and uses the McpUnity instance to communicate with Unity. It handles potential errors and returns the logs in a structured JSON format.

Test

N/A

Changes that Break Backward Compatibility

N/A

Documentation

While no explicit documentation changes are mentioned, the new tool's implementation includes inline comments and type definitions that serve as documentation for its usage and functionality.

Created with Palmier

Summary by CodeRabbit

  • New Features
    • Introduced a new tool that allows users to retrieve Unity console logs directly from the server, with optional filtering by log type (info, warning, error).

- Added getConsoleLogsTool.ts to provide console logs access through tools interface
- Reused existing Unity-side implementation to minimize code changes
- Maintained the same functionality as unity://logs resource
Copy link

cubic-dev-ai bot commented May 20, 2025

Your cubic subscription is currently inactive. Please reactivate your subscription to receive AI reviews and use cubic.

Copy link
Contributor

coderabbitai bot commented May 20, 2025

📝 Walkthrough

"""

Walkthrough

A new tool, get_console_logs, has been added to the MCP server, enabling retrieval of Unity console logs with optional filtering by log type. The tool is registered with the server, includes parameter validation, error handling, and logging, and integrates with the Unity communication layer for log retrieval.

Changes

File(s) Change Summary
Server~/src/tools/getConsoleLogsTool.ts
Server~/build/tools/getConsoleLogsTool.js
Introduced the get_console_logs tool, including registration logic, parameter validation, Unity communication, and error handling.
Server~/build/tools/getConsoleLogsTool.d.ts Added type declaration for registerGetConsoleLogsTool function, specifying its parameters and purpose.
Server~/src/index.ts
Server~/build/index.js
Imported and registered the new get_console_logs tool with the MCP server.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MCPServer
    participant McpUnity
    participant Unity

    Client->>MCPServer: Call get_console_logs tool (optional logType)
    MCPServer->>McpUnity: Request get_console_logs (logType)
    McpUnity->>Unity: Fetch console logs (logType)
    Unity-->>McpUnity: Return logs
    McpUnity-->>MCPServer: Respond with logs
    MCPServer-->>Client: Return logs as JSON text
Loading

Poem

A bunny hopped into the code,
To fetch console logs on the road.
With Unity’s chatter, now easy to see,
Debugging is swift as can be!
Through tools and with care,
Logs leap through the air,
Hooray for new features—yippee! 🐇
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 621d054 and 2331c6f.

📒 Files selected for processing (3)
  • Server~/build/tools/getConsoleLogsTool.d.ts (1 hunks)
  • Server~/build/tools/getConsoleLogsTool.js (1 hunks)
  • Server~/src/tools/getConsoleLogsTool.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Server~/build/tools/getConsoleLogsTool.d.ts
  • Server~/build/tools/getConsoleLogsTool.js
  • Server~/src/tools/getConsoleLogsTool.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch tool-unity-logs
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
Server~/build/tools/getConsoleLogsTool.js (2)

6-8: Consider constraining logType parameter values.

The parameter schema allows any string for logType, but the description mentions specific values (info, warning, error). Consider using an enum or explicitly validate these values to prevent unexpected inputs.

 const paramsSchema = z.object({
-    logType: z.string().optional().describe('The type of logs to retrieve (info, warning, error) - defaults to all logs if not specified')
+    logType: z.enum(['info', 'warning', 'error']).optional().describe('The type of logs to retrieve (info, warning, error) - defaults to all logs if not specified')
 });

54-59: Consider returning structured data instead of stringified JSON.

The current implementation returns the entire response as a JSON string. For better usability, consider extracting and returning only the relevant log data in a structured format, making it easier for consumers to process.

 return {
     content: [{
             type: 'text',
-            text: JSON.stringify(response, null, 2)
+            text: JSON.stringify(response.data, null, 2)
         }]
 };
Server~/src/tools/getConsoleLogsTool.ts (2)

31-41: Error handling looks good, but consider typed parameters

The error handling is well-implemented with proper logging. However, consider using a typed parameter object instead of any for better type safety.

- async (params: any) => {
+ async (params: z.infer<typeof paramsSchema>) => {

53-54: Add type safety to toolHandler parameters

Similar to the previous comment, use a typed parameter instead of any for better type safety.

- async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolResult> {
+ async function toolHandler(mcpUnity: McpUnity, params: z.infer<typeof paramsSchema>): Promise<CallToolResult> {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6403d7b and 621d054.

📒 Files selected for processing (5)
  • Server~/build/index.js (2 hunks)
  • Server~/build/tools/getConsoleLogsTool.d.ts (1 hunks)
  • Server~/build/tools/getConsoleLogsTool.js (1 hunks)
  • Server~/src/index.ts (2 hunks)
  • Server~/src/tools/getConsoleLogsTool.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Server~/build/index.js (1)
Server~/build/tools/getConsoleLogsTool.js (1)
  • registerGetConsoleLogsTool (17-32)
Server~/build/tools/getConsoleLogsTool.d.ts (3)
Server~/build/tools/getConsoleLogsTool.js (1)
  • registerGetConsoleLogsTool (17-32)
Server~/src/tools/getConsoleLogsTool.ts (1)
  • registerGetConsoleLogsTool (23-43)
Server~/build/index.js (2)
  • server (29-38)
  • mcpUnity (40-40)
🔇 Additional comments (9)
Server~/build/index.js (2)

11-11: Proper module import for the new tool.

The import is correctly placed alongside other tool imports, maintaining consistent code organization.


47-47: Tool registration follows existing pattern.

The registration of the new console logs tool is properly implemented and placed in the same section as other tool registrations, following the established pattern.

Server~/src/index.ts (2)

11-11: Clean import of the new console logs tool.

The import statement is properly positioned among other tool imports, maintaining code organization consistency.


54-54: Appropriate tool registration.

The new tool registration follows the same pattern as other tools and is correctly integrated into the server setup.

Server~/build/tools/getConsoleLogsTool.d.ts (1)

1-12: Well-documented TypeScript declaration.

The declaration file properly defines the function signature with appropriate JSDoc comments explaining the purpose and parameters. This enhances code maintainability and developer experience.

Server~/build/tools/getConsoleLogsTool.js (2)

17-32: Clean tool registration with proper logging.

The registration function follows the established pattern in the codebase with appropriate logging at each step. Error handling is robust, capturing and logging any failures during tool execution.


41-53: Effective implementation of Unity communication.

Good reuse of existing Unity-side implementation by using the same method name as the resource. The error handling is also robust, throwing a specific McpUnityError with a clear error message.

Server~/src/tools/getConsoleLogsTool.ts (2)

57-63: Good approach to reuse existing Unity-side implementation

The implementation correctly reuses the existing Unity-side code by using the same method name, which minimizes changes and maintains consistency.


1-7: Import structure looks good

The imports are well-organized and include all necessary dependencies for the tool implementation.

@twilight07 twilight07 closed this May 20, 2025
@twilight07 twilight07 deleted the tool-unity-logs branch May 20, 2025 13:15
@twilight07 twilight07 restored the tool-unity-logs branch May 20, 2025 13:48
@twilight07 twilight07 reopened this May 20, 2025
@twilight07
Copy link
Contributor Author

@CoderGamester
Copy link
Owner

Very good PR
This gives me the idea to create a tool for each resource

thank you for your contribution

@CoderGamester CoderGamester merged commit a648497 into CoderGamester:main May 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants