Skip to content

How To: Accept a complex/class object in a McpServerTool function #496

Closed
@ksaye

Description

@ksaye

Is your feature request related to a problem? Please describe.
I am unable to pass a complex object, as I can with OpenAPI, to a method.

the following code

using ModelContextProtocol.Server;
using System.ComponentModel;

namespace VoiceAgentWeb
{
    [McpServerToolType]
    public class AzureCommunicationServices
    {
        [McpServerTool, Description("Makes a phone call to the user.")]
        public static Task CallUser(PersonToCall person) {
            
            Console.WriteLine($"Calling the user {person.name}");

            return Task.CompletedTask;
        }

    }

    //[McpServerResourceType, Description("The person to call.")]
    public class PersonToCall
    {
        public required string? phoneNumber { get; set; }
        public required string? name { get; set; }
        public required string? greeting { get; set; }
    }
}

Copilot studio get confused about the name and the person record

Image

In MCP Inspector, I can manually pass the variables and it works:

Image

Also, if I change the code to a non complex object, it works:

using ModelContextProtocol.Server;
using System.ComponentModel;

namespace VoiceAgentWeb
{
    [McpServerToolType]
    public class AzureCommunicationServices
    {
        [McpServerTool, Description("Makes a phone call to the user.")]
        public static Task CallUser(string name, string greeting, string phonenumber)
        { 
            Console.WriteLine($"Calling the user {name}");
            Console.WriteLine($"Greeting: {greeting}");
            Console.WriteLine($"Phone Number: {phonenumber}");

            return Task.CompletedTask;
        }
    }
}

Image

I know OpenAPI defines the schema which helps the LLM. Is there something I am missing in MCP?

Describe the solution you'd like
I would like to provide the schema to the calling LLM for successful execution.

Describe alternatives you've considered
Either using OpenAPI or a non complex object.

Additional context
I hope I am just missing something in the code where this would work as defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions