formatting, more version rollbacks
This commit is contained in:
parent
37dcf753af
commit
9686fc2ead
2 changed files with 51 additions and 52 deletions
|
|
@ -34,7 +34,7 @@ server.tool(
|
|||
},
|
||||
required: ["celsius", "fahrenheit"]
|
||||
},
|
||||
conditions: {
|
||||
conditions: {
|
||||
type: "string",
|
||||
enum: ["sunny", "cloudy", "rainy", "stormy", "snowy"]
|
||||
},
|
||||
|
|
@ -57,7 +57,7 @@ server.tool(
|
|||
// Simulate weather API call
|
||||
const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10;
|
||||
const conditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"][Math.floor(Math.random() * 5)];
|
||||
|
||||
|
||||
return {
|
||||
structuredContent: {
|
||||
temperature: {
|
||||
|
|
@ -118,15 +118,15 @@ server.tool(
|
|||
const lines = csv_data.trim().split('\n');
|
||||
const headers = lines[0].split(delimiter).map(h => h.trim());
|
||||
const data = lines.slice(1).map(line => line.split(delimiter).map(cell => cell.trim()));
|
||||
|
||||
|
||||
// Infer data types
|
||||
const dataTypes: { [key: string]: string } = {};
|
||||
const summary: { [key: string]: unknown } = {};
|
||||
|
||||
|
||||
headers.forEach((header, idx) => {
|
||||
const values = data.map(row => row[idx]);
|
||||
const numericValues = values.filter(v => !isNaN(Number(v)) && v !== '');
|
||||
|
||||
|
||||
if (numericValues.length === values.length) {
|
||||
dataTypes[header] = "number";
|
||||
const numbers = numericValues.map(Number);
|
||||
|
|
@ -140,7 +140,7 @@ server.tool(
|
|||
dataTypes[header] = "string";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
structuredContent: {
|
||||
row_count: data.length,
|
||||
|
|
@ -174,7 +174,7 @@ server.tool(
|
|||
|
||||
// Tool that can return both structured and unstructured content
|
||||
server.tool(
|
||||
"hybrid_tool",
|
||||
"hybrid_tool",
|
||||
"Tool that returns both structured and readable content",
|
||||
{
|
||||
data: z.array(z.number()).describe("Array of numbers to analyze")
|
||||
|
|
@ -196,12 +196,12 @@ server.tool(
|
|||
async ({ data }) => {
|
||||
const mean = data.reduce((a, b) => a + b, 0) / data.length;
|
||||
const sorted = [...data].sort((a, b) => a - b);
|
||||
const median = sorted.length % 2 === 0
|
||||
const median = sorted.length % 2 === 0
|
||||
? (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2
|
||||
: sorted[Math.floor(sorted.length / 2)];
|
||||
const variance = data.reduce((acc, val) => acc + Math.pow(val - mean, 2), 0) / data.length;
|
||||
const std_dev = Math.sqrt(variance);
|
||||
|
||||
|
||||
return {
|
||||
structuredContent: {
|
||||
stats: {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|||
type: "object",
|
||||
properties: {
|
||||
bmi: { type: "number", description: "Body Mass Index" },
|
||||
category: {
|
||||
type: "string",
|
||||
category: {
|
||||
type: "string",
|
||||
enum: ["underweight", "normal", "overweight", "obese"],
|
||||
description: "BMI category"
|
||||
},
|
||||
|
|
@ -102,22 +102,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
|
|||
switch (request.params.name) {
|
||||
case "calculate_bmi": {
|
||||
const { height_cm, weight_kg } = request.params.arguments as { height_cm: number; weight_kg: number };
|
||||
|
||||
|
||||
const height_m = height_cm / 100;
|
||||
const bmi = weight_kg / (height_m * height_m);
|
||||
|
||||
|
||||
let category: string;
|
||||
if (bmi < 18.5) category = "underweight";
|
||||
else if (bmi < 25) category = "normal";
|
||||
else if (bmi < 30) category = "overweight";
|
||||
else category = "obese";
|
||||
|
||||
|
||||
// Calculate healthy weight range for normal BMI (18.5-24.9)
|
||||
const min_healthy_bmi = 18.5;
|
||||
const max_healthy_bmi = 24.9;
|
||||
const min_healthy_weight = min_healthy_bmi * height_m * height_m;
|
||||
const max_healthy_weight = max_healthy_bmi * height_m * height_m;
|
||||
|
||||
|
||||
// Return structured content matching the outputSchema
|
||||
return {
|
||||
structuredContent: {
|
||||
|
|
@ -130,31 +130,31 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
case "analyze_text": {
|
||||
const { text } = request.params.arguments as { text: string };
|
||||
|
||||
|
||||
// Simple text analysis
|
||||
const words = text.trim().split(/\s+/);
|
||||
const sentences = text.split(/[.!?]+/).filter(s => s.trim().length > 0);
|
||||
const wordsPerMinute = 200; // Average reading speed
|
||||
|
||||
|
||||
// Very simple sentiment analysis (for demo purposes)
|
||||
const positiveWords = ["good", "great", "excellent", "happy", "positive", "amazing"];
|
||||
const negativeWords = ["bad", "poor", "terrible", "sad", "negative", "awful"];
|
||||
|
||||
|
||||
let positiveCount = 0;
|
||||
let negativeCount = 0;
|
||||
words.forEach(word => {
|
||||
if (positiveWords.includes(word.toLowerCase())) positiveCount++;
|
||||
if (negativeWords.includes(word.toLowerCase())) negativeCount++;
|
||||
});
|
||||
|
||||
|
||||
let sentiment: string;
|
||||
if (positiveCount > negativeCount) sentiment = "positive";
|
||||
else if (negativeCount > positiveCount) sentiment = "negative";
|
||||
else sentiment = "neutral";
|
||||
|
||||
|
||||
// Extract key phrases (simple approach - just common bigrams)
|
||||
const keyPhrases: string[] = [];
|
||||
for (let i = 0; i < words.length - 1; i++) {
|
||||
|
|
@ -162,7 +162,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
|
|||
keyPhrases.push(`${words[i]} ${words[i + 1]}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
structuredContent: {
|
||||
word_count: words.length,
|
||||
|
|
@ -174,21 +174,21 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
case "traditional_tool": {
|
||||
const { message } = request.params.arguments as { message: string };
|
||||
|
||||
|
||||
// Traditional tool returns content array
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: `Processed message: ${message.toUpperCase()}`
|
||||
{
|
||||
type: "text",
|
||||
text: `Processed message: ${message.toUpperCase()}`
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
throw new McpError(
|
||||
ErrorCode.MethodNotFound,
|
||||
|
|
|
|||
Loading…
Reference in a new issue