Skip to content

Commit 5f04662

Browse files
br8thVincent Kyalo
andauthored
fix textcontent type serialization (#16)
Co-authored-by: Vincent Kyalo <vincentkyalo@microsoft.com>
1 parent 4b746c5 commit 5f04662

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

MCPSharp.Test/ClientTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public async Task TestCallTool()
4444

4545
string response = result.Content[0].Text;
4646
Assert.AreEqual("Echo: test", response);
47+
Assert.AreEqual("text", result.Content[0].Type);
48+
4749
}
4850

4951
[TestCategory("Prompts")]

MCPSharp.Test/STDIOTransportTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public async Task TestCallTool()
3232
{
3333
var result = await client.CallToolAsync("Hello");
3434
string response = result.Content[0].Text;
35+
3536
Assert.AreEqual("hello, claude.", response);
37+
Assert.AreEqual("text", result.Content[0].Type);
3638
}
3739

3840
[TestCategory("Tools")]
@@ -42,6 +44,8 @@ public async Task TestCallDynamicTool()
4244
var result = await client.CallToolAsync("dynamicTool", new Dictionary<string, object> { { "input", "test string" }, { "input2", "another string" } });
4345
string response = result.Content[0].Text;
4446
Assert.AreEqual("hello, test string.\nanother string", response);
47+
Assert.AreEqual("text", result.Content[0].Type);
48+
4549
}
4650

4751
[TestCategory("Tools")]
@@ -51,6 +55,8 @@ public async Task TestCallTool_semantic()
5155
var result = await client.CallToolAsync("SemanticTest");
5256
string response = result.Content[0].Text;
5357
Assert.AreEqual("success", response);
58+
Assert.AreEqual("text", result.Content[0].Type);
59+
5460
}
5561

5662
[TestCategory("Tools")]
@@ -61,6 +67,8 @@ public async Task TestCallToolWithParameters()
6167
Assert.IsFalse(result.IsError);
6268
string response = result.Content[0].Text;
6369
Assert.AreEqual("this is a test of the echo function", response);
70+
Assert.AreEqual("text", result.Content[0].Type);
71+
6472
}
6573

6674
[TestCategory("Misc")]
@@ -70,6 +78,8 @@ public async Task TestException()
7078
var result = await client.CallToolAsync("throw_exception");
7179
string response = result.Content[0].Text;
7280
Assert.AreEqual("This is an exception", response);
81+
Assert.AreEqual("text", result.Content[0].Type);
82+
7383
}
7484

7585
[TestCategory("Tools")]
@@ -94,6 +104,8 @@ public async Task TestCallExternalTool()
94104
var result = await client.CallToolAsync("dll-tool");
95105
string response = result.Content[0].Text;
96106
Assert.AreEqual("success", response);
107+
Assert.AreEqual("text", result.Content[0].Type);
108+
97109
}
98110

99111

@@ -131,6 +143,8 @@ public async Task TestCallToolWithParameterObject()
131143
var result = await client.CallToolAsync("AddComplex", new Dictionary<string, object> { { "obj", new ComplicatedObject { Name = "Claude", Age = 25, Hobbies = ["Programming", "Gaming"] } } });
132144
string response = result.Content[0].Text;
133145
Assert.AreEqual("Name: Claude, Age: 25, Hobbies: Programming, Gaming", response);
134-
}
146+
Assert.AreEqual("text", result.Content[0].Type);
147+
148+
}
135149
}
136150
}

MCPSharp/Model/Content/TextContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public class TextContent(string text = null)
99
/// The text of the message
1010
/// </summary>
1111
public string Text { get; set; } = text;
12-
1312
/// <summary>
1413
/// The type of the content. This is always "text"
1514
/// </summary>
16-
public const string Type = "text";
15+
public string Type { get; } = "text";
16+
1717
}
1818
}
1919

0 commit comments

Comments
 (0)