Skip to main content
Glama

MySQL Hub MCP Server

by CHOIJun-0613
server_app.pyβ€’4.4 kB
""" μ„œλ²„ 메인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ HTTP μ„œλ²„μ™€ MCP μ„œλ²„λ₯Ό κ΄€λ¦¬ν•©λ‹ˆλ‹€. """ import asyncio import logging import argparse import sys from typing import Optional from config import config from database import db_manager from ai_provider import ai_manager from mcp_server import run_mcp_server from http_server import run_http_server from common import clear_screen, init_environment #stdout을 clearν•˜κ³  μ‹œμž‘ clear_screen() logger = logging.getLogger(__name__) class ServerApp: """μ„œλ²„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 클래슀""" def __init__(self): self.http_task: Optional[asyncio.Task] = None self.mcp_task: Optional[asyncio.Task] = None async def start_http_server(self): """HTTP μ„œλ²„λ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€.""" try: await run_http_server() except Exception as e: logger.error(f"HTTP μ„œλ²„ μ‹œμž‘ μ‹€νŒ¨: {e}") raise async def start_mcp_server(self): """MCP μ„œλ²„λ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€.""" try: await run_mcp_server() except Exception as e: logger.error(f"MCP μ„œλ²„ μ‹œμž‘ μ‹€νŒ¨: {e}") raise async def run_both_servers(self): """HTTP μ„œλ²„μ™€ MCP μ„œλ²„λ₯Ό λ™μ‹œμ— μ‹€ν–‰ν•©λ‹ˆλ‹€.""" try: # 두 μ„œλ²„λ₯Ό λ™μ‹œμ— μ‹€ν–‰ self.http_task = asyncio.create_task(self.start_http_server()) self.mcp_task = asyncio.create_task(self.start_mcp_server()) logger.info("HTTP μ„œλ²„μ™€ MCP μ„œλ²„κ°€ μ‹œμž‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.") logger.info(f"HTTP μ„œλ²„: http://{config.SERVER_HOST}:{config.SERVER_PORT}") logger.info("MCP μ„œλ²„: stdio 톡신 μ€€λΉ„ μ™„λ£Œ") # 두 μ„œλ²„κ°€ μ™„λ£Œλ  λ•ŒκΉŒμ§€ λŒ€κΈ° await asyncio.gather(self.http_task, self.mcp_task) except Exception as e: logger.error(f"μ„œλ²„ μ‹€ν–‰ 쀑 였λ₯˜: {e}") raise finally: await self.cleanup() async def run_http_only(self): """HTTP μ„œλ²„λ§Œ μ‹€ν–‰ν•©λ‹ˆλ‹€.""" try: logger.info("\n\n🚨===== MySQL Hub HTTP Server μ‹œμž‘ =====\n") logger.debug("HTTP μ„œλ²„λ§Œ μ‹œμž‘ν•©λ‹ˆλ‹€.") await self.start_http_server() except Exception as e: logger.error(f"HTTP μ„œλ²„ μ‹€ν–‰ 쀑 였λ₯˜: {e}") raise finally: await self.cleanup() async def run_mcp_only(self): """MCP μ„œλ²„λ§Œ μ‹€ν–‰ν•©λ‹ˆλ‹€.""" try: logger.info("\n\n🚨===== MySQL Hub MCP Server μ‹œμž‘ =====\n") logger.debug("MCP μ„œλ²„λ§Œ μ‹œμž‘ν•©λ‹ˆλ‹€.") await self.start_mcp_server() except Exception as e: logger.error(f"MCP μ„œλ²„ μ‹€ν–‰ 쀑 였λ₯˜: {e}") raise finally: await self.cleanup() async def cleanup(self): """λ¦¬μ†ŒμŠ€λ₯Ό μ •λ¦¬ν•©λ‹ˆλ‹€.""" if self.http_task and not self.http_task.done(): self.http_task.cancel() if self.mcp_task and not self.mcp_task.done(): self.mcp_task.cancel() logger.info("μ„œλ²„κ°€ μ’…λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.") def main(): """메인 ν•¨μˆ˜""" parser = argparse.ArgumentParser(description="MySQL Hub MCP Server") parser.add_argument( "--mode", choices=["both", "http", "mcp"], default="both", help="μ‹€ν–‰ λͺ¨λ“œ (κΈ°λ³Έκ°’: both)" ) parser.add_argument( "--config", help="μ„€μ • 파일 경둜" ) args = parser.parse_args() try: # λ‘œκΉ… μ„€μ • #config.setup_logging() # μ„œλ²„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 생성 app = ServerApp() # λͺ¨λ“œμ— 따라 μ„œλ²„ μ‹€ν–‰ if args.mode == "both": asyncio.run(app.run_both_servers()) elif args.mode == "http": asyncio.run(app.run_http_only()) elif args.mode == "mcp": asyncio.run(app.run_mcp_only()) except KeyboardInterrupt: logger.info("μ‚¬μš©μžμ— μ˜ν•΄ μ„œλ²„κ°€ μ€‘λ‹¨λ˜μ—ˆμŠ΅λ‹ˆλ‹€.") except Exception as e: logger.error(f"μ„œλ²„ μ‹€ν–‰ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}") sys.exit(1) if __name__ == "__main__": main()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CHOIJun-0613/mysql-hub-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server