|
6 | 6 | "fmt" |
7 | 7 | "testing" |
8 | 8 |
|
| 9 | + "github.com/google/jsonschema-go/jsonschema" |
9 | 10 | "github.com/modelcontextprotocol/go-sdk/mcp" |
10 | 11 | "github.com/stretchr/testify/require" |
11 | 12 | ) |
@@ -1832,3 +1833,51 @@ func TestWithTools_DeprecatedAliasAndFeatureFlag(t *testing.T) { |
1832 | 1833 | t.Errorf("Flag ON: Expected new_tool (via alias), got %s", availableOn[0].Tool.Name) |
1833 | 1834 | } |
1834 | 1835 | } |
| 1836 | + |
| 1837 | +func TestWithInsidersMode(t *testing.T) { |
| 1838 | + // Create a tool with a jsonschema.Schema that has show_ui |
| 1839 | + toolWithShowUI := NewServerToolFromHandler( |
| 1840 | + mcp.Tool{ |
| 1841 | + Name: "test_tool", |
| 1842 | + InputSchema: &jsonschema.Schema{ |
| 1843 | + Type: "object", |
| 1844 | + Properties: map[string]*jsonschema.Schema{ |
| 1845 | + "show_ui": { |
| 1846 | + Type: "boolean", |
| 1847 | + Description: "Show UI", |
| 1848 | + }, |
| 1849 | + "owner": { |
| 1850 | + Type: "string", |
| 1851 | + Description: "Owner", |
| 1852 | + }, |
| 1853 | + }, |
| 1854 | + }, |
| 1855 | + }, |
| 1856 | + testToolsetMetadata("test"), |
| 1857 | + func(_ any) mcp.ToolHandler { |
| 1858 | + return func(_ context.Context, _ *mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 1859 | + return nil, nil |
| 1860 | + } |
| 1861 | + }, |
| 1862 | + ) |
| 1863 | + |
| 1864 | + tools := []ServerTool{toolWithShowUI} |
| 1865 | + |
| 1866 | + // Test with insiders mode disabled - show_ui should be stripped |
| 1867 | + regNoInsiders := mustBuild(t, NewBuilder().SetTools(tools).WithInsidersMode(false)) |
| 1868 | + toolsNoInsiders := regNoInsiders.AllTools() |
| 1869 | + require.Len(t, toolsNoInsiders, 1) |
| 1870 | + schema, ok := toolsNoInsiders[0].Tool.InputSchema.(*jsonschema.Schema) |
| 1871 | + require.True(t, ok, "Schema should be *jsonschema.Schema") |
| 1872 | + require.Nil(t, schema.Properties["show_ui"], "show_ui should be stripped when insiders mode is disabled") |
| 1873 | + require.NotNil(t, schema.Properties["owner"], "owner should still exist") |
| 1874 | + |
| 1875 | + // Test with insiders mode enabled - show_ui should remain |
| 1876 | + regWithInsiders := mustBuild(t, NewBuilder().SetTools(tools).WithInsidersMode(true)) |
| 1877 | + toolsWithInsiders := regWithInsiders.AllTools() |
| 1878 | + require.Len(t, toolsWithInsiders, 1) |
| 1879 | + schemaInsiders, ok := toolsWithInsiders[0].Tool.InputSchema.(*jsonschema.Schema) |
| 1880 | + require.True(t, ok, "Schema should be *jsonschema.Schema") |
| 1881 | + require.NotNil(t, schemaInsiders.Properties["show_ui"], "show_ui should remain when insiders mode is enabled") |
| 1882 | + require.NotNil(t, schemaInsiders.Properties["owner"], "owner should still exist") |
| 1883 | +} |
0 commit comments