K-Map-MCP

Iamlixinzhao/K-Map-MCP

3.1

If you are the rightful owner of K-Map-MCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

K-Map Solver with GPT-4o Integration

A comprehensive Karnaugh Map (K-Map) solver that integrates with OpenAI's GPT-4o model, enabling intelligent Boolean algebra simplification through natural language interaction.

Note: This project is based on the original KMapSolver by salmanmorshed, which is licensed under the GNU General Public License v2.0. This enhanced version adds GPT-4o integration and MCP server capabilities while maintaining the core K-Map solving functionality.

Features

  • Multiple Variable Support: Solves 2, 3, and 4 variable K-Maps
  • AI Integration: Powered by GPT-4o for intelligent problem understanding
  • Dual Interface: Both GUI and MCP API interfaces
  • Visual Output: Provides formatted K-Map visualizations
  • Educational: Includes detailed explanations and usage guides

Quick Start

python working_gpt_client.py

Installation

  1. Clone the repository:
git clone https://github.com/Iamlixinzhao/K-Map-MCP.git
cd KMapSolver
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up your OpenAI API key in the code files:
OPENAI_API_KEY = "your-api-key-here"

Usage Examples

Basic K-Map Solving

User: "Help me solve this 2-variable K-Map: [[1, 0], [0, 1]]"
GPT-4o: Returns simplified Boolean expression 

Knowledge Queries

User: "What is a K-Map?"
GPT-4o: Provides detailed explanation and usage instructions

Complex Problems

User: "Solve this 3-variable K-Map: [[1, 0, 0, 1], [0, 1, 1, 0]]"
GPT-4o: Analyzes and returns optimized solution

Project Structure

KMapSolver/
ā”œā”€ā”€ main.py                    # Original GUI program
ā”œā”€ā”€ guis.py                    # GUI interface code
ā”œā”€ā”€ solvers.py                 # Core K-Map solving algorithms
ā”œā”€ā”€ helpers.py                 # Helper functions
ā”œā”€ā”€ mcp_server.py              # MCP server implementation
ā”œā”€ā”€ simple_gpt_test.py         # Simplified GPT integration test
ā”œā”€ā”€ openai_kmap_client.py      # Full OpenAI integration
ā”œā”€ā”€ start_gpt_kmap.py          # Interactive launcher
ā”œā”€ā”€ test_mcp.py                # MCP server test
ā”œā”€ā”€ requirements.txt           # Python dependencies
ā”œā”€ā”€ kmap-solver.json          # MCP configuration
ā”œā”€ā”€ README.md                 # This file
ā”œā”€ā”€ README_MCP.md             # MCP server documentation
ā”œā”€ā”€ GPT_Integration_Guide.md   # GPT integration guide
└── GUI_vs_MCP_Comparison.md  # Interface comparison

MCP Server Tools

The MCP server provides the following tools:

  • solve_kmap_2: Solve 2-variable K-Maps (2x2 matrix)
  • solve_kmap_3: Solve 3-variable K-Maps (2x4 matrix)
  • solve_kmap_4: Solve 4-variable K-Maps (4x4 matrix)
  • get_kmap_info: Get detailed K-Map information and usage guide

Input Format

K-Map data should be provided as matrices:

  • 2 variables: 2x2 matrix [[1, 0], [0, 1]]
  • 3 variables: 2x4 matrix [[1, 0, 0, 1], [0, 1, 1, 0]]
  • 4 variables: 4x4 matrix

Values:

  • 0: False
  • 1: True
  • 2: Don't care (X)

Examples

2-Variable K-Map

Input: [[1, 0], [0, 1]] Output: F(A,B) = A'B + AB'

3-Variable K-Map

Input: [[1, 0, 0, 1], [0, 1, 1, 0]] Output: F(A,B,C) = A'B'C' + A'BC + AB'C + ABC'

Architecture

GUI Interface

  • Interactive graphical interface
  • Real-time visualization
  • Manual input through clicking
  • Immediate feedback

MCP API Interface

  • Programmatic API calls
  • Text-based output
  • Automated processing
  • Integration capabilities

GPT-4o Integration

  • Natural language understanding
  • Intelligent tool selection
  • Contextual responses
  • Educational explanations

Dependencies

  • wxPython: GUI framework
  • openai: OpenAI API client
  • mcp: Model Context Protocol
  • asyncio: Asynchronous programming

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the GNU General Public License v2.0 (GPL-2.0) - see the LICENSE.txt file for details.

Acknowledgments

This project is based on the original K-Map Solver implementation by salmanmorshed, which is licensed under the GNU General Public License v2.0.

Original Project

Additional Acknowledgments

  • OpenAI GPT-4o API for AI integration
  • Model Context Protocol (MCP) specification
  • wxPython GUI framework

Support

For issues and questions:

  1. Check the documentation files
  2. Review the example usage
  3. Test with the simplified version first
  4. Open an issue on GitHub

Note: Make sure to set your OpenAI API key before running the GPT integration features.