Skip to content

.Net: Bug: InvalidOperationException while using working with Playwright MCP Tools #11292

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

Closed
anuraj opened this issue Mar 31, 2025 · 0 comments · Fixed by #11309
Closed

.Net: Bug: InvalidOperationException while using working with Playwright MCP Tools #11292

anuraj opened this issue Mar 31, 2025 · 0 comments · Fixed by #11309
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@anuraj
Copy link

anuraj commented Mar 31, 2025

Describe the bug
I am working with MCP Playwright server - I am getting an exception like this

System.InvalidOperationException: 'The requested operation requires an element of type 'Boolean', but the target element has type 'Array'.'

To Reproduce
Steps to reproduce the behavior:

  1. Create a console app with .NET 8.0.
  2. Add reference of Microsoft.SemanticKernel (1.44.0) and ModelContextProtocol (0.1.0-preview.4) nuget package references.
  3. Use the following code.
var collection = new ServiceCollection();

var configuration = new ConfigurationBuilder()
    .AddUserSecrets<Program>()
    .Build();

var endpoint = configuration["GitHub:Endpoint"]!;
var apiKey = configuration["GitHub:Token"]!;
var deploymentName = "gpt-4o-mini";

collection.AddLogging(services => services.AddConsole().SetMinimumLevel(LogLevel.Debug));

collection.AddKernel()
    .AddAzureOpenAIChatCompletion(deploymentName, endpoint, apiKey);

var serviceProvider = collection.BuildServiceProvider();

var kernel = serviceProvider.GetRequiredService<Kernel>();

await using var playwrightMcpClient = await McpClientFactory.CreateAsync
(
    new()
    {
        Id = "playwright",
        Name = "Playwright",
        TransportType = "stdio",
        TransportOptions = new Dictionary<string, string>
        {
            ["command"] = "npx",
            ["arguments"] = "-y @executeautomation/playwright-mcp-server"
        },
    },
    new()
    {
        ClientInfo = new() { Name = "WebSiteTesterAgent", Version = "1.0.0" }
    }
);

var tools = await playwrightMcpClient.ListToolsAsync();
kernel.Plugins.AddFromFunctions("Playwright", tools.Select(t => t.AsKernelFunction()));
  1. See error
    Expected behavior
    It should not throw any exceptions.

Screenshots

Image

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel (1.44.0), ModelContextProtocol (0.1.0-preview.4)
  • AI model: GitHub Models - gpt-4o-mini
  • IDE: Visual Studio
  • OS: Windows

Additional context
It is happening for a specific tool - start_codegen_session. If I write a try-catch and ignore the exception it is working as expected - I am able to use this tool.

@anuraj anuraj added the bug Something isn't working label Mar 31, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Mar 31, 2025
@github-actions github-actions bot changed the title Bug: InvalidOperationException while using working with Playwright MCP Tools .Net: Bug: InvalidOperationException while using working with Playwright MCP Tools Mar 31, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 1, 2025
…11309)

### Motivation, Context and Description

This PR fixes the issue caused by accessing the `required` property
value as if it were a boolean property, instead of accessing it as an
array of strings. Additionally, it reads the `required` property from
the object root instead of reading it from each individual property of
the object because the `required` property is defined at the root level
to specify which properties are mandatory for the entire object.

So, when iterating over the object root level properties, the code now
uses the `"required": ["options"]` property declared at the root level
instead of the `"required": ["outputPath"]` declared at the `options`
property level.
```json
{
    "type": "object",
    "properties": {
        "options": {
            "type": "object",
            "description": "Code generation options",
            "properties": {
                "outputPath": {
                    "type": "string",
                    "description": "Directory path where generated tests will be saved (use absolute path)"
                },
                "testNamePrefix": {
                    "type": "string",
                    "description": "Prefix to use for generated test names (default: \u0027GeneratedTest\u0027)"
                },
                "includeComments": {
                    "type": "boolean",
                    "description": "Whether to include descriptive comments in generated tests"
                }
            },
            "required": [
                "outputPath"
            ]
        }
    },
    "required": [
        "options"
    ]
}
```
JsonSpec:
https://json-schema.org/understanding-json-schema/reference/object#required
Fixes: #11292
Contributes to:
#11212
eavanvalkenburg pushed a commit to eavanvalkenburg/semantic-kernel that referenced this issue Apr 2, 2025
…icrosoft#11309)

### Motivation, Context and Description

This PR fixes the issue caused by accessing the `required` property
value as if it were a boolean property, instead of accessing it as an
array of strings. Additionally, it reads the `required` property from
the object root instead of reading it from each individual property of
the object because the `required` property is defined at the root level
to specify which properties are mandatory for the entire object.

So, when iterating over the object root level properties, the code now
uses the `"required": ["options"]` property declared at the root level
instead of the `"required": ["outputPath"]` declared at the `options`
property level.
```json
{
    "type": "object",
    "properties": {
        "options": {
            "type": "object",
            "description": "Code generation options",
            "properties": {
                "outputPath": {
                    "type": "string",
                    "description": "Directory path where generated tests will be saved (use absolute path)"
                },
                "testNamePrefix": {
                    "type": "string",
                    "description": "Prefix to use for generated test names (default: \u0027GeneratedTest\u0027)"
                },
                "includeComments": {
                    "type": "boolean",
                    "description": "Whether to include descriptive comments in generated tests"
                }
            },
            "required": [
                "outputPath"
            ]
        }
    },
    "required": [
        "options"
    ]
}
```
JsonSpec:
https://json-schema.org/understanding-json-schema/reference/object#required
Fixes: microsoft#11292
Contributes to:
microsoft#11212
@SergeyMenshykh SergeyMenshykh moved this from Bug to Sprint: Done in Semantic Kernel Apr 3, 2025
glorious-beard pushed a commit to glorious-beard/semantic-kernel that referenced this issue Apr 6, 2025
…icrosoft#11309)

### Motivation, Context and Description

This PR fixes the issue caused by accessing the `required` property
value as if it were a boolean property, instead of accessing it as an
array of strings. Additionally, it reads the `required` property from
the object root instead of reading it from each individual property of
the object because the `required` property is defined at the root level
to specify which properties are mandatory for the entire object.

So, when iterating over the object root level properties, the code now
uses the `"required": ["options"]` property declared at the root level
instead of the `"required": ["outputPath"]` declared at the `options`
property level.
```json
{
    "type": "object",
    "properties": {
        "options": {
            "type": "object",
            "description": "Code generation options",
            "properties": {
                "outputPath": {
                    "type": "string",
                    "description": "Directory path where generated tests will be saved (use absolute path)"
                },
                "testNamePrefix": {
                    "type": "string",
                    "description": "Prefix to use for generated test names (default: \u0027GeneratedTest\u0027)"
                },
                "includeComments": {
                    "type": "boolean",
                    "description": "Whether to include descriptive comments in generated tests"
                }
            },
            "required": [
                "outputPath"
            ]
        }
    },
    "required": [
        "options"
    ]
}
```
JsonSpec:
https://json-schema.org/understanding-json-schema/reference/object#required
Fixes: microsoft#11292
Contributes to:
microsoft#11212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants