I am developing MCP tool in C# Asp.Net Core.
The LoginTool works correctly and returns a sessionId (see Image 1).
When calling PaymentTool, the sessionId is required (see Image 2), but it doesn’t appear to be passed properly, resulting in an error or incomplete workflow.
It works in Studio, but not in mcp-streamable mode within Copilot Studio.
I also added the following instruction to Copilot:
When you use the LoginTool, save the
sessionIdit returns. For every subsequent call to PaymentTool or CreditTool, include the samesessionIdin the parameters.
I’m looking to resolve this issue.
info:
title: MCP
description: >-
Provides .NET 8 MCP tools for searching, summarizing, and managing member access,
details. Designed for integration with .NET 8 projects.
version: 1.0.0
host: https://test.test.com/memberaccessinfo
basePath: /
schemes:
- https
consumes: []
produces: []
paths:
/:
post:
summary: MCP
x-ms-agentic-protocol: mcp-streamable-1.0
operationId: InvokeMCP
responses:
'200':
description: Success
definitions: {}
parameters: {}
responses: {}
securityDefinitions: {}
security: []
tags: []
public class LoginToolController
{
// Public static session store for per-login session management
public static readonly Dictionary<string, SessionData> SessionStore = new();
Name = "LoginTool",
Title = "User Login Tool",
UseStructuredContent = true
)]
[Description("A tool to authenticate users and provide session tokens.")]
public async Task<LoginResponse> LoginTool(string username, string password)
{
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
return new LoginResponse { Message = "Username and password are required." };
if (username == "demo" && password == "demo")
{
var sessionId = Guid.NewGuid().ToString();
// Store session data
SessionStore[sessionId] = new SessionData
{
LoginTime = DateTime.UtcNow
};
{
Success = true,
SessionId = sessionId,
Message = "Login successful"
};
return response;
}
else if (username == "demo1" && password == "demo1")
{
var sessionId = Guid.NewGuid().ToString();
// Store session data
SessionStore[sessionId] = new SessionData
{
Username = username,
LoginTime = DateTime.UtcNow,
sessionId= sessionId
};
{
Success = true,
SessionId = sessionId,
Message = "Login successful"
};
return response;
}
return new LoginResponse{Success = false, Message = "Invalid credentials" };
}
public static SessionData? GetSession(string sessionId)
{
SessionStore.TryGetValue(sessionId, out var session);
return session;
}
}
public class SessionData
{
[Description("Name of the member associated with the creditor information.")]
public string Username { get; set; } = "";
public string sessionId { get; set; } = "";
public DateTime LoginTime { get; set; }
}
{
[Description("Username provided by the user for authentication.")]
public string Username { get; set; } = "";
public string Password { get; set; } = "";
}
{
[Description("Indicates whether the login was successful.")]
public bool Success { get; set; }
public string? SessionId { get; set; }
public string Message { get; set; } = "";
}
public class PaymentToolController
{
[McpServerTool(
Name = "PaymentTool",
Title = "User Payment Tool",
UseStructuredContent = true
)]
[Description("Use this tool to process payments. Always include the 'sessionId' returned by the LoginTool result when calling this tool.")]
public async Task<PaymentResponse> PaymentTool(string sessionId)
{
if (string.IsNullOrWhiteSpace(sessionId))
return new PaymentResponse { Message = "SessionId missing. Please login first." };
var session = LoginToolController.GetSession(sessionId);
if (session == null)
return new PaymentResponse { Message = "Invalid or expired session. Please login again." };
{
// Simulate pulling payment data for the logged-in user
var response = new PaymentResponse
{
MemberName = session.Username,
sessionId = session.sessionId,
DueAmount = 150.75m,
DueDate = DateTime.UtcNow.AddDays(5),
Status = "Payment Pending"
};
}
else if (session.Username == "demo1")
{
// Simulate pulling payment data for the logged-in user
var response = new PaymentResponse
{
MemberName = session.Username,
sessionId = session.sessionId,
DueAmount = 123123,
DueDate = DateTime.UtcNow.AddDays(5),
Status = "Payment Approvded"
};
}
}
}
{
public string SessionId { get; set; } = "";
}
{
[Description("Name of the member associated with the creditor information.")]
public string MemberName { get; set; } = "";
public string sessionId { get; set; } = "";
public decimal DueAmount { get; set; }
public DateTime DueDate { get; set; }
public string Status { get; set; } = "";
public string Message { get; set; } = "";
}

Report
All responses (
Answers (