Skip to content

Commit 512412e

Browse files
committed
update for resources-bug-fix
1 parent 02912ad commit 512412e

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

MCPForUnity/Editor/Windows/Components/Advanced/McpAdvancedSection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class McpAdvancedSection
4444
public event Action OnGitUrlChanged;
4545
public event Action OnHttpServerCommandUpdateRequested;
4646
public event Action OnTestConnectionRequested;
47+
public event Action OnPackageDeployed;
4748

4849
public VisualElement Root { get; private set; }
4950

@@ -489,6 +490,7 @@ private void OnDeployClicked()
489490
else
490491
{
491492
EditorUtility.DisplayDialog("Deployment Complete", result.Message + (string.IsNullOrEmpty(result.BackupPath) ? string.Empty : $"\nBackup: {result.BackupPath}"), "OK");
493+
OnPackageDeployed?.Invoke();
492494
}
493495

494496
UpdateDeploymentSection();
@@ -506,6 +508,7 @@ private void OnRestoreBackupClicked()
506508
else
507509
{
508510
EditorUtility.DisplayDialog("Restore Complete", result.Message, "OK");
511+
OnPackageDeployed?.Invoke();
509512
}
510513

511514
UpdateDeploymentSection();

MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ public void CreateGUI()
275275
if (connectionSection != null)
276276
await connectionSection.VerifyBridgeConnectionAsync();
277277
};
278+
advancedSection.OnPackageDeployed += () =>
279+
{
280+
UpdateVersionLabel();
281+
QueueUpdateCheck();
282+
};
278283
// Wire up health status updates from Connection to Advanced
279284
connectionSection?.SetHealthStatusUpdateCallback((isHealthy, statusText) =>
280285
advancedSection?.UpdateHealthStatus(isHealthy, statusText));

Server/src/services/resources/__init__.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
22
MCP Resources package - Auto-discovers and registers all resources in this directory.
33
"""
4+
import functools
45
import inspect
56
import logging
67
from pathlib import Path
78

89
from fastmcp import FastMCP
10+
from pydantic import BaseModel
911
from core.telemetry_decorator import telemetry_resource
1012
from core.logging_decorator import log_execution
1113

@@ -18,6 +20,25 @@
1820
__all__ = ['register_all_resources']
1921

2022

23+
def _serialize_pydantic(func):
24+
"""Wrap a resource function so Pydantic models are serialized to JSON strings.
25+
26+
FastMCP 3.x expects resource functions to return str, bytes, or ResourceResult.
27+
Our resource functions return MCPResponse (a Pydantic BaseModel). This wrapper
28+
converts them to JSON strings automatically.
29+
"""
30+
@functools.wraps(func)
31+
async def wrapper(*args, **kwargs):
32+
result = await func(*args, **kwargs)
33+
if isinstance(result, BaseModel):
34+
return result.model_dump_json()
35+
if isinstance(result, dict):
36+
import json
37+
return json.dumps(result)
38+
return result
39+
return wrapper
40+
41+
2142
def register_all_resources(mcp: FastMCP, *, project_scoped_tools: bool = True):
2243
"""
2344
Auto-discover and register all resources in the resources/ directory.
@@ -55,7 +76,8 @@ def register_all_resources(mcp: FastMCP, *, project_scoped_tools: bool = True):
5576
has_query_params = '{?' in uri
5677

5778
if has_query_params:
58-
wrapped_template = log_execution(resource_name, "Resource")(func)
79+
wrapped_template = _serialize_pydantic(func)
80+
wrapped_template = log_execution(resource_name, "Resource")(wrapped_template)
5981
wrapped_template = telemetry_resource(
6082
resource_name)(wrapped_template)
6183
wrapped_template = mcp.resource(
@@ -69,7 +91,8 @@ def register_all_resources(mcp: FastMCP, *, project_scoped_tools: bool = True):
6991
registered_count += 1
7092
resource_info['func'] = wrapped_template
7193
else:
72-
wrapped = log_execution(resource_name, "Resource")(func)
94+
wrapped = _serialize_pydantic(func)
95+
wrapped = log_execution(resource_name, "Resource")(wrapped)
7396
wrapped = telemetry_resource(resource_name)(wrapped)
7497
wrapped = mcp.resource(
7598
uri=uri,

Server/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)