File size: 1,867 Bytes
d0608f3
 
 
 
373d4af
5b01595
 
108b731
 
5b01595
 
 
6578e67
108b731
 
b76362d
 
77c770f
5b01595
 
 
 
 
9f10db4
5b01595
 
 
 
 
b738859
0dcd607
5b01595
13e60f0
5b01595
eb26e42
5b01595
108b731
5b01595
 
eb26e42
4d6b475
 
 
 
 
eb26e42
 
 
 
88f13ad
88032dc
eb26e42
 
7deefa2
 
 
b738859
5b01595
7a35ebc
5b01595
f645072
5b01595
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# References:

# https://docs.crewai.com/introduction

import json, os
from agents.mcp.mcp_client import (
    call_mcp_tool,
    MCP_SSE_URL_CHESS_POSITION_EVALUATION,
    MCP_TOOL_CHESS_POSITION_EVALUATION
)
from crewai.tools import tool

class MCPTools():           
    # Chess position evaluation
    
    @tool("Best Move Tool")
    def best_move_tool(fen: str) -> str:
        """Get best move with continuation in UCI notation for chess position in FEN.
        
        Args:
            fen (str): Chess position in FEN

        Returns:
            str: Best move with continuation in UCI notation (e.g., 'f7f2 e4e5 f2f1')

        Raises:
            RuntimeError: If processing fails

        """
        print(f"🛠️ MCPTools: best_move_tool: fen={fen}")
        
        try:
            mcp_url = os.getenv("MCP_SSE_URL", MCP_SSE_URL_CHESS_POSITION_EVALUATION)
            
            raw_result = call_mcp_tool(
                mcp_url=mcp_url,
                tool_name=MCP_TOOL_CHESS_POSITION_EVALUATION,
                arguments={"fen": fen}
            )

            if isinstance(raw_result, str):
                try:
                    raw_result = eval(raw_result)
                except:
                    pass
            
            if isinstance(raw_result, tuple) and len(raw_result) > 0:
                raw_result = raw_result[0]
            
            result = None

            if isinstance(raw_result, dict) and "continuation" in raw_result:
                result = raw_result["continuation"]
            else:
                result = raw_result

            print(f"🛠️ MCPTools: best_move_tool: result={result}")
    
            return result
        except Exception as e:
            print(f"⚠️ MCPTools: best_move_tool: exception={str(e)}")
            raise RuntimeError(f"Processing failed: {str(e)}")